1 """DataUpdateCoordinator for Plugwise."""
3 from datetime
import timedelta
5 from packaging.version
import Version
6 from plugwise
import PlugwiseData, Smile
7 from plugwise.exceptions
import (
13 UnsupportedDeviceError,
25 from .const
import DEFAULT_PORT, DEFAULT_USERNAME, DOMAIN, GATEWAY_ID, LOGGER
29 """Class to manage fetching Plugwise data from single endpoint."""
31 _connected: bool =
False
33 config_entry: ConfigEntry
35 def __init__(self, hass: HomeAssistant) ->
None:
36 """Initialize the coordinator."""
54 username=self.
config_entryconfig_entry.data.get(CONF_USERNAME, DEFAULT_USERNAME),
55 password=self.
config_entryconfig_entry.data[CONF_PASSWORD],
56 port=self.
config_entryconfig_entry.data.get(CONF_PORT, DEFAULT_PORT),
63 """Connect to the Plugwise Smile."""
64 version = await self.
apiapi.connect()
67 self.
apiapi.get_all_gateway_entities()
70 """Fetch data from Plugwise."""
71 data = PlugwiseData(devices={}, gateway={})
76 except ConnectionFailedError
as err:
78 except InvalidAuthentication
as err:
80 except (InvalidXMLError, ResponseError)
as err:
82 "Invalid XML data, or error indication received from the Plugwise Adam/Smile/Stretch"
84 except PlugwiseError
as err:
85 raise UpdateFailed(
"Data incomplete or missing")
from err
86 except UnsupportedDeviceError
as err:
94 """Add new Plugwise devices, remove non-existing devices."""
104 """Clean registries when removed devices found."""
105 device_reg = dr.async_get(self.
hasshass)
106 device_list = dr.async_entries_for_config_entry(
110 gateway_device = device_reg.async_get_device(
111 {(DOMAIN, data.gateway[GATEWAY_ID])}
113 assert gateway_device
is not None
114 via_device_id = gateway_device.id
117 for device_entry
in device_list:
118 for identifier
in device_entry.identifiers:
119 if identifier[0] == DOMAIN:
121 device_entry.via_device_id == via_device_id
122 and identifier[1]
not in data.devices
124 device_reg.async_update_device(
125 device_entry.id, remove_config_entry_id=entry.entry_id
128 "Removed %s device %s %s from device_registry",
PlugwiseData _async_update_data(self)
None _async_add_remove_devices(self, PlugwiseData data, ConfigEntry entry)
None _async_remove_devices(self, PlugwiseData data, ConfigEntry entry)
None __init__(self, HomeAssistant hass)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)