22
33from datetime import timedelta
44
5- from plugwise import PlugwiseData , Smile
5+ from plugwise import GwEntityData , Smile
66from plugwise .exceptions import (
77 ConnectionFailedError ,
88 InvalidAuthentication ,
2828from homeassistant .helpers .update_coordinator import DataUpdateCoordinator , UpdateFailed
2929from packaging .version import Version
3030
31- from .const import DEFAULT_SCAN_INTERVAL , DOMAIN , GATEWAY_ID , LOGGER
31+ from .const import DEFAULT_SCAN_INTERVAL , DOMAIN , LOGGER
3232
3333
34- class PlugwiseDataUpdateCoordinator (DataUpdateCoordinator [PlugwiseData ]):
34+ class PlugwiseDataUpdateCoordinator (DataUpdateCoordinator [dict [ str , GwEntityData ] ]):
3535 """Class to manage fetching Plugwise data from single endpoint."""
3636
3737 _connected : bool = False
@@ -78,7 +78,6 @@ async def _connect(self) -> None:
7878 version = await self .api .connect ()
7979 self ._connected = isinstance (version , Version )
8080 if self ._connected :
81- self .api .get_all_gateway_entities ()
8281 self .update_interval = DEFAULT_SCAN_INTERVAL .get (
8382 self .api .smile_type , timedelta (seconds = 60 )
8483 ) # pw-beta options scan-interval
@@ -89,9 +88,8 @@ async def _connect(self) -> None:
8988
9089 LOGGER .debug ("DUC update interval: %s" , self .update_interval ) # pw-beta options
9190
92- async def _async_update_data (self ) -> PlugwiseData :
91+ async def _async_update_data (self ) -> dict [ str , GwEntityData ] :
9392 """Fetch data from Plugwise."""
94- data = PlugwiseData (devices = {}, gateway = {})
9593 try :
9694 if not self ._connected :
9795 await self ._connect ()
@@ -122,31 +120,34 @@ async def _async_update_data(self) -> PlugwiseData:
122120 translation_domain = DOMAIN ,
123121 translation_key = "unsupported_firmware" ,
124122 ) from err
125- else :
126- LOGGER .debug (f"{ self .api .smile_name } data: %s" , data )
127- await self .async_add_remove_devices (data , self .config_entry )
128123
124+ LOGGER .debug (f"{ self .api .smile_name } data: %s" , data )
125+ await self ._async_add_remove_devices (data , self .config_entry )
129126 return data
130127
131- async def async_add_remove_devices (self , data : PlugwiseData , entry : ConfigEntry ) -> None :
128+ async def _async_add_remove_devices (
129+ self , data : dict [str , GwEntityData ], entry : ConfigEntry
130+ ) -> None :
132131 """Add new Plugwise devices, remove non-existing devices."""
133132 # Check for new or removed devices
134- self .new_devices = set (data . devices ) - self ._current_devices
135- removed_devices = self ._current_devices - set (data . devices )
136- self ._current_devices = set (data . devices )
133+ self .new_devices = set (data ) - self ._current_devices
134+ removed_devices = self ._current_devices - set (data )
135+ self ._current_devices = set (data )
137136
138137 if removed_devices :
139- await self .async_remove_devices (data , entry )
138+ await self ._async_remove_devices (data , entry )
140139
141- async def async_remove_devices (self , data : PlugwiseData , entry : ConfigEntry ) -> None :
140+ async def _async_remove_devices (
141+ self , data : dict [str , GwEntityData ], entry : ConfigEntry
142+ ) -> None :
142143 """Clean registries when removed devices found."""
143144 device_reg = dr .async_get (self .hass )
144145 device_list = dr .async_entries_for_config_entry (
145146 device_reg , self .config_entry .entry_id
146147 )
147148
148149 # First find the Plugwise via_device
149- gateway_device = device_reg .async_get_device ({(DOMAIN , data . gateway [ GATEWAY_ID ] )})
150+ gateway_device = device_reg .async_get_device ({(DOMAIN , self . api . gateway_id )})
150151 if gateway_device is not None :
151152 via_device_id = gateway_device .id
152153
@@ -156,7 +157,7 @@ async def async_remove_devices(self, data: PlugwiseData, entry: ConfigEntry) ->
156157 if identifier [0 ] == DOMAIN :
157158 if (
158159 device_entry .via_device_id == via_device_id
159- and identifier [1 ] not in data . devices
160+ and identifier [1 ] not in data
160161 ):
161162 device_reg .async_update_device (
162163 device_entry .id , remove_config_entry_id = entry .entry_id
0 commit comments