def connect_to_alarm(self) -> bool: import custom_components.visonic.pyvisonic as visonicApi # Connection to python Library if self.SystemStarted: return # remove any existing visonic related sensors (so we don't get entity id already exists exceptions on a restart) sensor_list = self.hass.states.async_entity_ids("binary_sensor") if sensor_list is not None: for x in sensor_list: _LOGGER.info("Checking HA Entity ID: {0}".format(x)) if x.lower().startswith( 'binary_sensor.visonic_z' ): #device, entity = self.split_entity(x) #self.entities[device][entity] _LOGGER.info(" Removed existing HA Entity ID: {0}".format(x)) self.hass.add_job(self.hass.states.async_remove(x)) # set up config parameters in the visonic library self.hass.data[DOMAIN][DOMAINDATA]["Exception Count"] = self.panel_exception_counter #_LOGGER.info("connect_to_alarm self.config = {1} {2} {0}".format(self.config, CONF_DOWNLOAD_CODE, self.config.get(CONF_DOWNLOAD_CODE))) # Get Visonic specific configuration. device_type = self.config.get(CONF_DEVICE_TYPE) #_LOGGER.info("Visonic Connection Device Type is {0} {1}".format(device_type, self.getConfigData())) # update config parameters (local in hass[DOMAIN] mainly) self.updateConfig() self.comm = None # Connect in the way defined by the user in the config file, ethernet or usb if device_type == "ethernet": host = self.config.get(CONF_HOST) port = self.config.get(CONF_PORT) self.comm = visonicApi.create_tcp_visonic_connection(address = host, port = port, client = self, panelConfig = self.getConfigData(), event_callback = self.visonic_event_callback_handler, disconnect_callback = self.disconnect_callback, loop = self.hass.loop) elif device_type == "usb": path = self.config.get(CONF_PATH) baud = self.config.get(CONF_DEVICE_BAUD) self.comm = visonicApi.create_usb_visonic_connection(path = path, baud = baud, client = self, panelConfig = self.getConfigData(), event_callback = self.visonic_event_callback_handler, disconnect_callback = self.disconnect_callback, loop = self.hass.loop) if self.comm is not None: self.myTask = self.hass.loop.create_task(self.comm) self.SystemStarted = True return True self.myTask = None message = 'Failed to connect into Visonic Alarm. Check Settings.' _LOGGER.error(message) self.hass.components.persistent_notification.create( message, title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID) return False
def connect_to_alarm(): global panel_reset_counter # remove any existing visonic related sensors (so we don't get entity id already exists exceptions on a restart) retval = hass.states.async_remove('switch.visonic_alarm_panel') if retval: _LOGGER.info( "Removed existing HA Entity ID: switch.visonic_alarm_panel") retval = hass.states.async_remove('alarm_control_panel.visonic_alarm') if retval: _LOGGER.info( "Removed existing HA Entity ID: alarm_control_panel.visonic_alarm" ) sensor_list = hass.states.async_entity_ids("binary_sensor") if sensor_list is not None: for x in sensor_list: if x.startswith('binary_sensor.visonic'): retval = hass.states.async_remove(x) if retval: _LOGGER.info( "Removed existing HA Entity ID: {0}".format(x)) # Set the Sensors list as empty hass.data[VISONIC_SENSORS] = {} for domain in VISONIC_COMPONENTS: hass.data[VISONIC_SENSORS][domain] = [] # set up config parameters in the visonic library visonicApi.setConfig("MotionOffDelay", config.get(CONF_MOTION_OFF_DELAY)) visonicApi.setConfig("PluginLanguage", config.get(CONF_LANGUAGE)) visonicApi.setConfig("ForceStandard", config.get(CONF_FORCE_STANDARD)) visonicApi.setConfig("AutoSyncTime", config.get(CONF_AUTO_SYNC_TIME)) visonicApi.setConfig("EnableRemoteArm", config.get(CONF_ENABLE_REMOTE_ARM)) visonicApi.setConfig("EnableRemoteDisArm", config.get(CONF_ENABLE_REMOTE_DISARM)) visonicApi.setConfig("EnableSensorBypass", config.get(CONF_ENABLE_SENSOR_BYPASS)) visonicApi.setConfig("OverrideCode", config.get(CONF_OVERRIDE_CODE)) visonicApi.setConfig("ResetCounter", panel_reset_counter) # Get Visonic specific configuration. device_type = config.get(CONF_DEVICE) hass.data[VISONIC_PLATFORM]["command_queue"] = command_queue hass.data[VISONIC_PLATFORM]["arm_without_code"] = config.get( CONF_ARM_CODE_AUTO) _LOGGER.info( "Visonic Connection Device Type is {0}".format(device_type)) comm = None # Connect in the way defined by the user in the config file, ethernet or usb if device_type["type"] == "ethernet": host = device_type[CONF_HOST] port = device_type[CONF_PORT] comm = visonicApi.create_tcp_visonic_connection( address=host, port=port, event_callback=visonic_event_callback_handler, command_queue=command_queue, disconnect_callback=disconnect_callback, loop=hass.loop) elif device_type["type"] == "usb": path = device_type[CONF_PATH] baud = device_type[CONF_DEVICE_BAUD] comm = visonicApi.create_usb_visonic_connection( port=path, baud=baud, event_callback=visonic_event_callback_handler, command_queue=command_queue, disconnect_callback=disconnect_callback, loop=hass.loop) if comm is not None: #wibble = hass.states.entity_ids() #for x in wibble: # _LOGGER.info("Wibble is {0}".format(x)) notused = hass.loop.create_task(comm) return True message = 'Failed to connect into Visonic Alarm. Check Settings.' _LOGGER.error(message) hass.components.persistent_notification.create( message, title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID) return False
def connect_to_alarm(): global SystemStarted if SystemStarted: return global panel_reset_counter global command_queue global myTask # remove any existing visonic related sensors (so we don't get entity id already exists exceptions on a restart) sensor_list = hass.states.async_entity_ids("binary_sensor") if sensor_list is not None: for x in sensor_list: _LOGGER.info("Checking HA Entity ID: {0}".format(x)) if x.lower().startswith( 'binary_sensor.visonic_z' ): #device, entity = self.split_entity(x) #self.entities[device][entity] _LOGGER.info(" Removed existing HA Entity ID: {0}".format(x)) # entity_object = get_entity(x) hass.add_job(hass.states.async_remove(x)) # Set the Sensors list as empty hass.data[VISONIC_SENSORS] = {} for domain in VISONIC_COMPONENTS: hass.data[VISONIC_SENSORS][domain] = [] # set up config parameters in the visonic library visonicApi.setConfig("MotionOffDelay", config.get(CONF_MOTION_OFF_DELAY)) visonicApi.setConfig("PluginLanguage", config.get(CONF_LANGUAGE)) visonicApi.setConfig("ForceStandard", config.get(CONF_FORCE_STANDARD)) visonicApi.setConfig("AutoSyncTime", config.get(CONF_AUTO_SYNC_TIME)) visonicApi.setConfig("EnableRemoteArm", config.get(CONF_ENABLE_REMOTE_ARM)) visonicApi.setConfig("EnableRemoteDisArm", config.get(CONF_ENABLE_REMOTE_DISARM)) visonicApi.setConfig("EnableSensorBypass", config.get(CONF_ENABLE_SENSOR_BYPASS)) visonicApi.setConfig("OverrideCode", config.get(CONF_OVERRIDE_CODE)) visonicApi.setConfig("DownloadCode", config.get(CONF_DOWNLOAD_CODE)) visonicApi.setConfig("ArmWithoutCode", config.get(CONF_ARM_CODE_AUTO)) visonicApi.setConfig("ResetCounter", panel_reset_counter) visonicApi.setConfig("ForceKeypad", config.get(CONF_FORCE_KEYPAD)) visonicApi.setConfig("B0_Enable", config.get(CONF_B0_ENABLE_MOTION_PROCESSING)) visonicApi.setConfig("B0_Min_Interval_Time", config.get(CONF_B0_MIN_TIME_BETWEEN_TRIGGERS)) visonicApi.setConfig("B0_Max_Wait_Time", config.get(CONF_B0_MAX_TIME_FOR_TRIGGER_EVENT)) # Get Visonic specific configuration. device_type = config.get(CONF_DEVICE) hass.data[VISONIC_PLATFORM]["command_queue"] = command_queue hass.data[VISONIC_PLATFORM]["arm_without_code"] = config.get(CONF_ARM_CODE_AUTO) hass.data[VISONIC_PLATFORM]["force_keypad"] = config.get(CONF_FORCE_KEYPAD) _LOGGER.info("Visonic Connection Device Type is {0}".format(device_type)) comm = None # Connect in the way defined by the user in the config file, ethernet or usb if device_type["type"] == "ethernet": host = device_type[CONF_HOST] port = device_type[CONF_PORT] comm = visonicApi.create_tcp_visonic_connection(address = host, port = port, event_callback = visonic_event_callback_handler, command_queue = command_queue, disconnect_callback = disconnect_callback, loop = hass.loop) elif device_type["type"] == "usb": path = device_type[CONF_PATH] baud = device_type[CONF_DEVICE_BAUD] comm = visonicApi.create_usb_visonic_connection(port = path, baud = baud, event_callback = visonic_event_callback_handler, command_queue = command_queue, disconnect_callback = disconnect_callback, loop = hass.loop) if comm is not None: #wibble = hass.states.entity_ids() #for x in wibble: # _LOGGER.info("Wibble is {0}".format(x)) SystemStarted = True myTask = hass.loop.create_task(comm) return True myTask = None message = 'Failed to connect into Visonic Alarm. Check Settings.' _LOGGER.error(message) hass.components.persistent_notification.create( message, title=NOTIFICATION_TITLE, notification_id=NOTIFICATION_ID) return False