def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the NX584 binary sensor platform.""" from nx584 import client as nx584_client host = config.get(CONF_HOST) port = config.get(CONF_PORT) exclude = config.get(CONF_EXCLUDE_ZONES) zone_types = config.get(CONF_ZONE_TYPES) try: client = nx584_client.Client(f"http://{host}:{port}") zones = client.list_zones() except requests.exceptions.ConnectionError as ex: _LOGGER.error("Unable to connect to NX584: %s", str(ex)) return False version = [int(v) for v in client.get_version().split(".")] if version < [1, 1]: _LOGGER.error("NX584 is too old to use for sensors (>=0.2 required)") return False zone_sensors = { zone["number"]: NX584ZoneSensor(zone, zone_types.get(zone["number"], "opening")) for zone in zones if zone["number"] not in exclude } if zone_sensors: add_entities(zone_sensors.values()) watcher = NX584Watcher(client, zone_sensors) watcher.start() else: _LOGGER.warning("No zones found on NX584") return True
def __init__(self, hass, host, name): from nx584 import client self._hass = hass self._host = host self._name = name self._alarm = client.Client('http://%s' % host) # Do an initial list operation so that we will try to actually # talk to the API and trigger a requests exception for setup_platform() # to catch self._alarm.list_zones()
def __init__(self, hass, url, name): """Initalize the nx584 alarm panel.""" from nx584 import client self._hass = hass self._name = name self._url = url self._alarm = client.Client(self._url) # Do an initial list operation so that we will try to actually # talk to the API and trigger a requests exception for setup_platform() # to catch self._alarm.list_zones()
def setup_platform(hass, config, add_devices, discovery_info=None): """Setup nx584 binary sensor platform.""" from nx584 import client as nx584_client host = config.get('host', 'localhost:5007') exclude = config.get('exclude_zones', []) zone_types = config.get('zone_types', {}) if not all(isinstance(zone, int) for zone in exclude): _LOGGER.error('Invalid excluded zone specified (use zone number)') return False if not all( isinstance(zone, int) and ztype in SENSOR_CLASSES for zone, ztype in zone_types.items()): _LOGGER.error('Invalid zone_types entry') return False try: client = nx584_client.Client('http://%s' % host) zones = client.list_zones() except requests.exceptions.ConnectionError as ex: _LOGGER.error('Unable to connect to NX584: %s', str(ex)) return False version = [int(v) for v in client.get_version().split('.')] if version < [1, 1]: _LOGGER.error('NX584 is too old to use for sensors (>=0.2 required)') return False zone_sensors = { zone['number']: NX584ZoneSensor(zone, zone_types.get(zone['number'], 'opening')) for zone in zones if zone['number'] not in exclude } if zone_sensors: add_devices(zone_sensors.values()) watcher = NX584Watcher(client, zone_sensors) watcher.start() else: _LOGGER.warning('No zones found on NX584') return True
async def async_setup_platform( hass: HomeAssistant, config: ConfigType, async_add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the NX584 platform.""" name = config.get(CONF_NAME) host = config.get(CONF_HOST) port = config.get(CONF_PORT) url = f"http://{host}:{port}" try: alarm_client = client.Client(url) await hass.async_add_executor_job(alarm_client.list_zones) except requests.exceptions.ConnectionError as ex: _LOGGER.error( "Unable to connect to %(host)s: %(reason)s", { "host": url, "reason": ex }, ) raise PlatformNotReady from ex entity = NX584Alarm(name, alarm_client, url) async_add_entities([entity]) platform = entity_platform.async_get_current_platform() platform.async_register_entity_service( SERVICE_BYPASS_ZONE, {vol.Required(ATTR_ZONE): cv.positive_int}, "alarm_bypass", ) platform.async_register_entity_service( SERVICE_UNBYPASS_ZONE, {vol.Required(ATTR_ZONE): cv.positive_int}, "alarm_unbypass", )
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): """Set up the NX584 platform.""" name = config.get(CONF_NAME) host = config.get(CONF_HOST) port = config.get(CONF_PORT) url = f"http://{host}:{port}" try: alarm_client = client.Client(url) await hass.async_add_executor_job(alarm_client.list_zones) except requests.exceptions.ConnectionError as ex: _LOGGER.error( "Unable to connect to %(host)s: %(reason)s", dict(host=url, reason=ex), ) raise PlatformNotReady from ex entity = NX584Alarm(name, alarm_client, url) async_add_entities([entity]) platform = entity_platform.current_platform.get() platform.async_register_entity_service( SERVICE_BYPASS_ZONE, {vol.Required(ATTR_ZONE): cv.positive_int}, "alarm_bypass", ) platform.async_register_entity_service( SERVICE_UNBYPASS_ZONE, {vol.Required(ATTR_ZONE): cv.positive_int}, "alarm_unbypass", )
def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the NX584 binary sensor platform.""" host = config[CONF_HOST] port = config[CONF_PORT] exclude = config[CONF_EXCLUDE_ZONES] zone_types = config[CONF_ZONE_TYPES] try: client = nx584_client.Client(f"http://{host}:{port}") zones = client.list_zones() except requests.exceptions.ConnectionError as ex: _LOGGER.error("Unable to connect to NX584: %s", str(ex)) return version = [int(v) for v in client.get_version().split(".")] if version < [1, 1]: _LOGGER.error("NX584 is too old to use for sensors (>=0.2 required)") return zone_sensors = { zone["number"]: NX584ZoneSensor( zone, zone_types.get(zone["number"], BinarySensorDeviceClass.OPENING)) for zone in zones if zone["number"] not in exclude } if zone_sensors: add_entities(zone_sensors.values()) watcher = NX584Watcher(client, zone_sensors) watcher.start() else: _LOGGER.warning("No zones found on NX584")