1 """Support for a Genius Hub system."""
3 from __future__
import annotations
5 from datetime
import timedelta
9 from geniushubclient
import GeniusHub
10 import voluptuous
as vol
30 from .const
import DOMAIN
32 _LOGGER = logging.getLogger(__name__)
37 MAC_ADDRESS_REGEXP =
r"^([0-9A-F]{2}:){5}([0-9A-F]{2})$"
39 ATTR_ZONE_MODE =
"mode"
40 ATTR_DURATION =
"duration"
42 SVC_SET_ZONE_MODE =
"set_zone_mode"
43 SVC_SET_ZONE_OVERRIDE =
"set_zone_override"
45 SET_ZONE_MODE_SCHEMA = vol.Schema(
47 vol.Required(ATTR_ENTITY_ID): cv.entity_id,
48 vol.Required(ATTR_ZONE_MODE): vol.In([
"off",
"timer",
"footprint"]),
51 SET_ZONE_OVERRIDE_SCHEMA = vol.Schema(
53 vol.Required(ATTR_ENTITY_ID): cv.entity_id,
54 vol.Required(ATTR_TEMPERATURE): vol.All(
55 vol.Coerce(float), vol.Range(min=4, max=28)
57 vol.Optional(ATTR_DURATION): vol.All(
65 Platform.BINARY_SENSOR,
69 Platform.WATER_HEATER,
73 type GeniusHubConfigEntry = ConfigEntry[GeniusBroker]
77 """Create a Genius Hub system."""
78 if CONF_TOKEN
in entry.data
and CONF_MAC
in entry.data:
79 entity_registry = er.async_get(hass)
80 registry_entries = er.async_entries_for_config_entry(
81 entity_registry, entry.entry_id
83 for reg_entry
in registry_entries:
84 if reg_entry.unique_id.startswith(entry.data[CONF_MAC]):
85 entity_registry.async_update_entity(
87 new_unique_id=reg_entry.unique_id.replace(
88 entry.data[CONF_MAC], entry.entry_id
93 if CONF_HOST
in entry.data:
95 entry.data[CONF_HOST],
96 username=entry.data[CONF_USERNAME],
97 password=entry.data[CONF_PASSWORD],
101 client = GeniusHub(entry.data[CONF_TOKEN], session=session)
103 unique_id = entry.unique_id
or entry.entry_id
105 broker = entry.runtime_data =
GeniusBroker(hass, client, unique_id)
108 await client.update()
109 except aiohttp.ClientResponseError
as err:
110 _LOGGER.error(
"Setup failed, check your configuration, %s", err)
112 broker.make_debug_log_entries()
118 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
125 """Set up the service functions."""
127 @verify_domain_control(hass, DOMAIN)
128 async
def set_zone_mode(call: ServiceCall) ->
None:
129 """Set the system mode."""
130 entity_id = call.data[ATTR_ENTITY_ID]
132 registry = er.async_get(hass)
133 registry_entry = registry.async_get(entity_id)
135 if registry_entry
is None or registry_entry.platform != DOMAIN:
136 raise ValueError(f
"'{entity_id}' is not a known {DOMAIN} entity")
138 if registry_entry.domain !=
"climate":
139 raise ValueError(f
"'{entity_id}' is not an {DOMAIN} zone")
142 "unique_id": registry_entry.unique_id,
143 "service": call.service,
149 hass.services.async_register(
150 DOMAIN, SVC_SET_ZONE_MODE, set_zone_mode, schema=SET_ZONE_MODE_SCHEMA
152 hass.services.async_register(
153 DOMAIN, SVC_SET_ZONE_OVERRIDE, set_zone_mode, schema=SET_ZONE_OVERRIDE_SCHEMA
158 """Container for geniushub client and data."""
160 def __init__(self, hass: HomeAssistant, client: GeniusHub, hub_uid: str) ->
None:
161 """Initialize the geniushub client."""
168 """Update the geniushub client's data."""
173 _LOGGER.warning(
"Connection to geniushub re-established")
175 aiohttp.ClientResponseError,
176 aiohttp.client_exceptions.ClientConnectorError,
181 "Connection to geniushub failed (unable to update), message is: %s",
190 """Make any useful debug log entries."""
192 "Raw JSON: \n\nclient._zones = %s \n\nclient._devices = %s",
194 self.
clientclient._devices,
None make_debug_log_entries(self)
None __init__(self, HomeAssistant hass, GeniusHub client, str hub_uid)
None async_update(self, now, **kwargs)
def setup_service_functions(HomeAssistant hass, broker)
bool async_setup_entry(HomeAssistant hass, GeniusHubConfigEntry entry)
IssData update(pyiss.ISS iss)
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)
None async_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)