def _create_binary_sensor(hass: HomeAssistant, knx_module: XKNX, config: ConfigType) -> XknxBinarySensor: """Return a KNX binary sensor to be used within XKNX.""" device_name = config[CONF_NAME] actions = [] automations = config.get(BinarySensorSchema.CONF_AUTOMATION) if automations is not None: for automation in automations: counter = automation[BinarySensorSchema.CONF_COUNTER] hook = automation[BinarySensorSchema.CONF_HOOK] action = automation[BinarySensorSchema.CONF_ACTION] script_name = f"{device_name} turn ON script" script = Script(hass, action, script_name, DOMAIN) action = XknxActionCallback(knx_module, script.async_run, hook=hook, counter=counter) actions.append(action) return XknxBinarySensor( knx_module, name=device_name, group_address_state=config[BinarySensorSchema.CONF_STATE_ADDRESS], sync_state=config[BinarySensorSchema.CONF_SYNC_STATE], device_class=config.get(CONF_DEVICE_CLASS), ignore_internal_state=config[ BinarySensorSchema.CONF_IGNORE_INTERNAL_STATE], reset_after=config.get(BinarySensorSchema.CONF_RESET_AFTER), actions=actions, )
def _create_binary_sensor(knx_module: XKNX, config: ConfigType) -> XknxBinarySensor: """Return a KNX binary sensor to be used within XKNX.""" device_name = config[CONF_NAME] return XknxBinarySensor( knx_module, name=device_name, group_address_state=config[BinarySensorSchema.CONF_STATE_ADDRESS], sync_state=config[BinarySensorSchema.CONF_SYNC_STATE], device_class=config.get(CONF_DEVICE_CLASS), ignore_internal_state=config[BinarySensorSchema.CONF_IGNORE_INTERNAL_STATE], context_timeout=config[BinarySensorSchema.CONF_CONTEXT_TIMEOUT], reset_after=config.get(BinarySensorSchema.CONF_RESET_AFTER), )
def __init__(self, xknx: XKNX, config: ConfigType) -> None: """Initialize of KNX binary sensor.""" self._device: XknxBinarySensor super().__init__(device=XknxBinarySensor( xknx, name=config[CONF_NAME], group_address_state=config[BinarySensorSchema.CONF_STATE_ADDRESS], invert=config[BinarySensorSchema.CONF_INVERT], sync_state=config[BinarySensorSchema.CONF_SYNC_STATE], ignore_internal_state=config[ BinarySensorSchema.CONF_IGNORE_INTERNAL_STATE], context_timeout=config.get( BinarySensorSchema.CONF_CONTEXT_TIMEOUT), reset_after=config.get(BinarySensorSchema.CONF_RESET_AFTER), )) self._device_class: str | None = config.get(CONF_DEVICE_CLASS) self._unique_id = f"{self._device.remote_value.group_address_state}"