1 """Support for EcoNet products."""
4 from datetime
import timedelta
7 from aiohttp.client_exceptions
import ClientError
8 from pyeconet
import EcoNetApiInterface
9 from pyeconet.equipment
import EquipmentType
10 from pyeconet.errors
import (
12 InvalidCredentialsError,
13 InvalidResponseFormat,
24 from .const
import API_CLIENT, DOMAIN, EQUIPMENT, PUSH_UPDATE
26 _LOGGER = logging.getLogger(__name__)
29 Platform.BINARY_SENSOR,
33 Platform.WATER_HEATER,
40 """Set up EcoNet as config entry."""
42 email = config_entry.data[CONF_EMAIL]
43 password = config_entry.data[CONF_PASSWORD]
46 api = await EcoNetApiInterface.login(email, password=password)
47 except InvalidCredentialsError:
48 _LOGGER.error(
"Invalid credentials provided")
50 except PyeconetError
as err:
51 _LOGGER.error(
"Config entry failed: %s", err)
52 raise ConfigEntryNotReady
from err
55 equipment = await api.get_equipment_by_type(
56 [EquipmentType.WATER_HEATER, EquipmentType.THERMOSTAT]
58 except (ClientError, GenericHTTPError, InvalidResponseFormat)
as err:
59 raise ConfigEntryNotReady
from err
60 hass.data.setdefault(DOMAIN, {API_CLIENT: {}, EQUIPMENT: {}})
61 hass.data[DOMAIN][API_CLIENT][config_entry.entry_id] = api
62 hass.data[DOMAIN][EQUIPMENT][config_entry.entry_id] = equipment
64 await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
68 def update_published():
69 """Handle a push update."""
72 for _eqip
in equipment[EquipmentType.WATER_HEATER]:
73 _eqip.set_update_callback(update_published)
75 for _eqip
in equipment[EquipmentType.THERMOSTAT]:
76 _eqip.set_update_callback(update_published)
78 async
def resubscribe(now):
79 """Resubscribe to the MQTT updates."""
80 await hass.async_add_executor_job(api.unsubscribe)
84 await asyncio.sleep(60)
85 await api.refresh_equipment()
93 """Unload a EcoNet config entry."""
94 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
96 hass.data[DOMAIN][API_CLIENT].pop(entry.entry_id)
97 hass.data[DOMAIN][EQUIPMENT].pop(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, ConfigEntry config_entry)
None dispatcher_send(HomeAssistant hass, str signal, *Any args)
CALLBACK_TYPE async_track_time_interval(HomeAssistant hass, Callable[[datetime], Coroutine[Any, Any, None]|None] action, timedelta interval, *str|None name=None, bool|None cancel_on_shutdown=None)