1 """Support for KNX/IP binary sensors."""
3 from __future__
import annotations
7 from xknx.devices
import BinarySensor
as XknxBinarySensor
9 from homeassistant
import config_entries
25 from .
import KNXModule
26 from .const
import ATTR_COUNTER, ATTR_SOURCE, KNX_MODULE_KEY
27 from .entity
import KnxYamlEntity
28 from .schema
import BinarySensorSchema
34 async_add_entities: AddEntitiesCallback,
36 """Set up the KNX binary sensor platform."""
37 knx_module = hass.data[KNX_MODULE_KEY]
38 config: list[ConfigType] = knx_module.config_yaml[Platform.BINARY_SENSOR]
46 """Representation of a KNX binary sensor."""
48 _device: XknxBinarySensor
50 def __init__(self, knx_module: KNXModule, config: ConfigType) ->
None:
51 """Initialize of KNX binary sensor."""
53 knx_module=knx_module,
54 device=XknxBinarySensor(
56 name=config[CONF_NAME],
57 group_address_state=config[BinarySensorSchema.CONF_STATE_ADDRESS],
58 invert=config[BinarySensorSchema.CONF_INVERT],
59 sync_state=config[BinarySensorSchema.CONF_SYNC_STATE],
60 ignore_internal_state=config[
61 BinarySensorSchema.CONF_IGNORE_INTERNAL_STATE
63 context_timeout=config.get(BinarySensorSchema.CONF_CONTEXT_TIMEOUT),
64 reset_after=config.get(BinarySensorSchema.CONF_RESET_AFTER),
73 """Restore last state."""
77 )
and last_state.state
not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
78 self.
_device_device.remote_value.update_value(last_state.state == STATE_ON)
82 """Return true if the binary sensor is on."""
87 """Return device specific state attributes."""
88 attr: dict[str, Any] = {}
90 if self.
_device_device.counter
is not None:
91 attr[ATTR_COUNTER] = self.
_device_device.counter
92 if self.
_device_device.last_telegram
is not None:
93 attr[ATTR_SOURCE] =
str(self.
_device_device.last_telegram.source_address)
None __init__(self, KNXModule knx_module, ConfigType config)
dict[str, Any]|None extra_state_attributes(self)
None async_added_to_hass(self)
State|None async_get_last_state(self)
None async_setup_entry(HomeAssistant hass, config_entries.ConfigEntry config_entry, AddEntitiesCallback async_add_entities)