1 """Update coordinator for HomeWizard."""
3 from __future__
import annotations
7 from homewizard_energy
import HomeWizardEnergyV1
8 from homewizard_energy.errors
import DisabledError, RequestError, UnsupportedError
9 from homewizard_energy.v1.const
import SUPPORTS_IDENTIFY, SUPPORTS_STATE
10 from homewizard_energy.v1.models
import Device
18 from .const
import DOMAIN, UPDATE_INTERVAL, DeviceResponseEntry
20 _LOGGER = logging.getLogger(__name__)
24 """Gather data for the energy device."""
26 api: HomeWizardEnergyV1
27 api_disabled: bool =
False
29 _unsupported_error: bool =
False
31 config_entry: ConfigEntry
37 """Initialize update coordinator."""
38 super().
__init__(hass, _LOGGER, name=DOMAIN, update_interval=UPDATE_INTERVAL)
39 self.
apiapi = HomeWizardEnergyV1(
45 """Fetch all device and sensor data from api."""
54 data.state = await self.
apiapi.
state()
56 data.system = await self.
apiapi.system()
58 except UnsupportedError
as ex:
63 "%s is running an outdated firmware version (%s). Contact HomeWizard support to update your device",
68 except RequestError
as ex:
70 ex, translation_domain=DOMAIN, translation_key=
"communication_error"
73 except DisabledError
as ex:
80 self.
hasshass.config_entries.async_schedule_reload(
85 ex, translation_domain=DOMAIN, translation_key=
"api_disabled"
94 """Return True if the device supports state."""
99 return device.product_type
in SUPPORTS_STATE
102 """Return True if the device supports identify."""
106 return device.product_type
in SUPPORTS_IDENTIFY
DeviceResponseEntry _async_update_data(self)
None __init__(self, HomeAssistant hass)
bool supports_state(self, Device|None device=None)
bool supports_identify(self, Device|None device=None)
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)
bool state(HomeAssistant hass, str|State|None entity, Any req_state, timedelta|None for_period=None, str|None attribute=None, TemplateVarsType variables=None)