async def async_setup(self) -> bool: entry = self.config_entry port = ( entry.options.get(CONF_SERVER_PORT, entry.data.get(CONF_SERVER_PORT)) or 0 ) _LOGGER.debug("Initializing Hubitat hub with event server on port %s", port) self._hub = HubitatHub(self.host, self.app_id, self.token, port) await self._hub.start() hub = self._hub hass = self.hass config_entry = self.config_entry for component in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(config_entry, component) ) _LOGGER.debug(f"Registered platforms") # Create an entity for the Hubitat hub with basic hub information hass.states.async_set( self.entity_id, "connected", { CONF_ID: f"{hub.host}::{hub.app_id}", CONF_HOST: hub.host, ATTR_HIDDEN: True, CONF_TEMPERATURE_UNIT: self.temperature_unit, }, ) return True
async def validate_input(data: Dict[str, Any]) -> Dict[str, Any]: """Validate that the user input allows us to connect.""" # data has the keys from CONFIG_SCHEMA with values provided by the user. host: str = data[CONF_HOST] app_id: str = data[CONF_APP_ID] token: str = data[CONF_ACCESS_TOKEN] hub = HubitatHub(host, app_id, token) await hub.check_config() return {"label": f"Hubitat ({get_hub_short_id(hub)})"}
async def async_setup(self) -> bool: """Initialize this hub instance.""" entry = self.config_entry url = entry.options.get(CONF_SERVER_URL, entry.data.get(CONF_SERVER_URL)) port = entry.options.get(CONF_SERVER_PORT, entry.data.get(CONF_SERVER_PORT)) # Previous versions of the integration may have saved a value of "" for # server_url with the assumption that a use_server_url flag would control # it's use. The current version uses a value of null for "no user URL" # rather than a flag. if url == "": url = None _LOGGER.debug("Initializing Hubitat hub with event server on port %s", port) self._hub = HubitatHub(self.host, self.app_id, self.token, port=port, event_url=url) await self._hub.start() hub = self._hub hass = self.hass config_entry = self.config_entry for platform in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup( config_entry, platform)) _LOGGER.debug("Registered platforms") # Create an entity for the Hubitat hub with basic hub information hass.states.async_set( self.entity_id, "connected", { CONF_ID: f"{hub.host}::{hub.app_id}", CONF_HOST: hub.host, ATTR_HIDDEN: True, CONF_TEMPERATURE_UNIT: self.temperature_unit, }, ) return True
async def _validate_input(user_input: Dict[str, Any]) -> Dict[str, Any]: """Validate that the user input can create a working connection.""" # data has the keys from CONFIG_SCHEMA with values provided by the user. host: str = user_input[CONF_HOST] app_id: str = user_input[CONF_APP_ID] token: str = user_input[CONF_ACCESS_TOKEN] port: Optional[int] = user_input.get(CONF_SERVER_PORT) event_url: Optional[str] = user_input.get(CONF_SERVER_URL) if event_url: event_url = cv.url(event_url) hub = HubitatHub(host, app_id, token, port=port, event_url=event_url) await hub.check_config() return {"label": f"Hubitat ({get_hub_short_id(hub)})", "hub": hub}
async def validate_input(user_input: Dict[str, Any]) -> Dict[str, Any]: """Validate that the user input allows us to connect.""" # data has the keys from CONFIG_SCHEMA with values provided by the user. host: str = user_input[CONF_HOST] app_id: str = user_input[CONF_APP_ID] token: str = user_input[CONF_ACCESS_TOKEN] port: int = user_input[CONF_SERVER_PORT] url: Optional[str] = user_input[CONF_SERVER_URL] use_url: bool = user_input[CONF_USE_SERVER_URL] event_url = url if use_url else None hub = HubitatHub(host, app_id, token, port=port, event_url=event_url) await hub.check_config() return {"label": f"Hubitat ({get_hub_short_id(hub)})"}
async def async_setup(self) -> bool: """Initialize this hub instance.""" entry = self.config_entry url = entry.options.get(CONF_SERVER_URL, entry.data.get(CONF_SERVER_URL)) port = entry.options.get(CONF_SERVER_PORT, entry.data.get(CONF_SERVER_PORT)) # Previous versions of the integration may have saved a value of "" for # server_url with the assumption that a use_server_url flag would control # it's use. The current version uses a value of null for "no user URL" # rather than a flag. if url == "": url = None ssl_cert = entry.options.get(CONF_SERVER_SSL_CERT, entry.data.get(CONF_SERVER_SSL_CERT)) ssl_key = entry.options.get(CONF_SERVER_SSL_KEY, entry.data.get(CONF_SERVER_SSL_KEY)) ssl_context = _create_ssl_context(ssl_cert, ssl_key) _LOGGER.debug( "Initializing Hubitat hub with event server on port %s with SSL %s", port, "disabled" if ssl_context is None else "enabled", ) self._hub = HubitatHub( self.host, self.app_id, self.token, port=port, event_url=url, ssl_context=ssl_context, ) await self._hub.start() self._hub_device_listeners: list[Listener] = [] self._device_listeners: dict[str, list[Listener]] = {} hub = self._hub hass = self.hass config_entry = self.config_entry # setup proxy Device representing the hub that can be used for linked # entities self.device = Device({ "id": self.id, "label": HUB_DEVICE_NAME, "name": HUB_DEVICE_NAME, "attributes": [ { "name": "mode", "currentValue": None, "dataType": "ENUM", }, { "name": "hsm_status", "currentValue": None, "dataType": "ENUM", }, ], "capabilities": [], "commands": [], }) # Add a listener for every device exported by the hub. The listener # will re-export the Hubitat event as a hubitat_event in HA if it # matches a trigger condition. for device_id in hub.devices: hub.add_device_listener(device_id, self.handle_event) # Update device identifiers to include the Maker API instance ID to # ensure that devices coming from separate hubs (or Maker API installs) # are handled properly. _update_device_ids(self.id, self.hass) # Initialize entities for platform in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup( config_entry, platform)) _LOGGER.debug("Registered platforms") # Create an entity for the Hubitat hub with basic hub information hass.states.async_set( self.entity_id, "connected", { CONF_ID: f"{hub.host}::{hub.app_id}", CONF_HOST: hub.host, ATTR_HIDDEN: True, CONF_TEMPERATURE_UNIT: self.temperature_unit, }, ) if self.mode_supported: def handle_mode_event(event: Event): self.device.update_attr("mode", cast(str, event.value)) for listener in self._hub_device_listeners: listener(event) self._hub.add_mode_listener(handle_mode_event) if self.mode: self.device.update_attr("mode", self.mode) if self.hsm_supported: def handle_hsm_status_event(event: Event): self.device.update_attr("hsm_status", cast(str, event.value)) for listener in self._hub_device_listeners: listener(event) self._hub.add_hsm_listener(handle_hsm_status_event) if self.hsm_status: self.device.update_attr("hsm_status", self.hsm_status) return True