async def async_connect(self, now=None): """Connect to and setup a Konnected device.""" if self.connected: return if self.cancel_connect_retry: # cancel any pending connect attempt and try now self.cancel_connect_retry() try: self.client = konnected.Client( host=self.host, port=str(self.port), websession=aiohttp_client.async_get_clientsession(self.opp), ) self.status = await self.client.get_status() self.api_version = KONN_API_VERSIONS.get( self.status.get("model", KONN_MODEL), KONN_API_VERSIONS[KONN_MODEL] ) _LOGGER.info( "Connected to new %s device", self.status.get("model", "Konnected") ) _LOGGER.debug(self.status) await self.async_update_initial_states() # brief delay to allow processing of recent status req await asyncio.sleep(0.1) await self.async_sync_device_config() except self.client.ClientError as err: _LOGGER.warning("Exception trying to connect to panel: %s", err) # retry in a bit, never more than ~3 min self.connect_attempts += 1 self.cancel_connect_retry = self.opp.helpers.event.async_call_later( 2 ** min(self.connect_attempts, 5) * 5, self.async_connect ) return self.connect_attempts = 0 self.connected = True _LOGGER.info( "Set up Konnected device %s. Open http://%s:%s in a " "web browser to view device status", self.device_id, self.host, self.port, ) device_registry = await dr.async_get_registry(self.opp) device_registry.async_get_or_create( config_entry_id=self.config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, self.status.get("mac"))}, identifiers={(DOMAIN, self.device_id)}, manufacturer="Konnected.io", name=self.config_entry.title, model=self.config_entry.title, sw_version=self.status.get("swVersion"), )
def __init__(self, hass, host, port): """Initialize the Konnected device.""" self.hass = hass self.host = host self.port = port self.client = konnected.Client(host, str(port)) self.status = self.client.get_status()
async def get_status(hass, host, port): """Get the status of a Konnected Panel.""" client = konnected.Client(host, str(port), aiohttp_client.async_get_clientsession(hass)) try: return await client.get_status() except client.ClientError as err: _LOGGER.error("Exception trying to get panel status: %s", err) raise CannotConnect
def __init__(self, hass, host, port, config): """Initialize the Konnected device.""" self.hass = hass self.host = host self.port = port self.user_config = config import konnected self.client = konnected.Client(host, str(port)) self.status = self.client.get_status() _LOGGER.info('Initialized Konnected device %s', self.device_id)
def __init__(self, config): self.id = config.name self.ip = config.get('ip', "127.0.0.1") self.port = config.get('port', 65000) self.total_pins = config.getint('pins', 0) self.total_zones = config.getint('zones', 0) self.konnected_client = konnected.Client(self.ip, self.port) self.zones = {} self.input_pins = {} self.output_pins = {} self._heart_beat_check = SensorLivenessCheck(self) self._heart_beat_check.start()
async def async_connect(self): """Connect to and setup a Konnected device.""" try: self.client = konnected.Client( host=self.host, port=str(self.port), websession=aiohttp_client.async_get_clientsession(self.hass), ) self.status = await self.client.get_status() self.api_version = KONN_API_VERSIONS.get( self.status.get("model", KONN_MODEL), KONN_API_VERSIONS[KONN_MODEL] ) _LOGGER.info( "Connected to new %s device", self.status.get("model", "Konnected") ) _LOGGER.debug(self.status) await self.async_update_initial_states() # brief delay to allow processing of recent status req await asyncio.sleep(0.1) await self.async_sync_device_config() except self.client.ClientError as err: _LOGGER.warning("Exception trying to connect to panel: %s", err) raise CannotConnect _LOGGER.info( "Set up Konnected device %s. Open http://%s:%s in a " "web browser to view device status", self.device_id, self.host, self.port, ) device_registry = await dr.async_get_registry(self.hass) device_registry.async_get_or_create( config_entry_id=self.config_entry.entry_id, connections={(dr.CONNECTION_NETWORK_MAC, self.status.get("mac"))}, identifiers={(DOMAIN, self.device_id)}, manufacturer="Konnected.io", name=self.config_entry.title, model=self.config_entry.title, sw_version=self.status.get("swVersion"), )