1 """Support for AlarmDecoder zone states- represented as binary sensors."""
10 from .
import AlarmDecoderConfigEntry
26 from .entity
import AlarmDecoderEntity
28 _LOGGER = logging.getLogger(__name__)
30 ATTR_RF_BIT0 =
"rf_bit0"
31 ATTR_RF_LOW_BAT =
"rf_low_battery"
32 ATTR_RF_SUPERVISED =
"rf_supervised"
33 ATTR_RF_BIT3 =
"rf_bit3"
34 ATTR_RF_LOOP3 =
"rf_loop3"
35 ATTR_RF_LOOP2 =
"rf_loop2"
36 ATTR_RF_LOOP4 =
"rf_loop4"
37 ATTR_RF_LOOP1 =
"rf_loop1"
42 entry: AlarmDecoderConfigEntry,
43 async_add_entities: AddEntitiesCallback,
45 """Set up for AlarmDecoder sensor."""
47 client = entry.runtime_data.client
48 zones = entry.options.get(OPTIONS_ZONES, DEFAULT_ZONE_OPTIONS)
51 for zone_num
in zones:
52 zone_info = zones[zone_num]
53 zone_type = zone_info[CONF_ZONE_TYPE]
54 zone_name = zone_info[CONF_ZONE_NAME]
55 zone_rfid = zone_info.get(CONF_ZONE_RFID)
56 zone_loop = zone_info.get(CONF_ZONE_LOOP)
57 relay_addr = zone_info.get(CONF_RELAY_ADDR)
58 relay_chan = zone_info.get(CONF_RELAY_CHAN)
69 entities.append(entity)
75 """Representation of an AlarmDecoder binary sensor."""
77 _attr_should_poll =
False
90 """Initialize the binary_sensor."""
92 self.
_attr_unique_id_attr_unique_id = f
"{client.serial_number}-zone-{zone_number}"
107 """Register callbacks."""
131 """Update the zone's state, if needed."""
137 """Update the zone's state, if needed."""
143 """Update RF state."""
144 if self.
_rfid_rfid
and message
and message.serial_number == self.
_rfid_rfid:
145 rfstate = message.value
148 attr = {CONF_ZONE_NUMBER: self.
_zone_number_zone_number}
149 if self.
_rfid_rfid
and rfstate
is not None:
150 attr[ATTR_RF_BIT0] =
bool(rfstate & 0x01)
151 attr[ATTR_RF_LOW_BAT] =
bool(rfstate & 0x02)
152 attr[ATTR_RF_SUPERVISED] =
bool(rfstate & 0x04)
153 attr[ATTR_RF_BIT3] =
bool(rfstate & 0x08)
154 attr[ATTR_RF_LOOP3] =
bool(rfstate & 0x10)
155 attr[ATTR_RF_LOOP2] =
bool(rfstate & 0x20)
156 attr[ATTR_RF_LOOP4] =
bool(rfstate & 0x40)
157 attr[ATTR_RF_LOOP1] =
bool(rfstate & 0x80)
162 """Update relay / expander state."""
167 "Relay" if message.type == message.RELAY
else "ZoneExpander",
def _rel_message_callback(self, message)
def _restore_callback(self, zone)
def _rfx_message_callback(self, message)
_attr_extra_state_attributes
def __init__(self, client, zone_number, zone_name, zone_type, zone_rfid, zone_loop, relay_addr, relay_chan)
None async_added_to_hass(self)
def _fault_callback(self, zone)
None async_on_remove(self, CALLBACK_TYPE func)
None schedule_update_ha_state(self, bool force_refresh=False)
None async_setup_entry(HomeAssistant hass, AlarmDecoderConfigEntry entry, AddEntitiesCallback async_add_entities)
Callable[[], None] async_dispatcher_connect(HomeAssistant hass, str signal, Callable[..., Any] target)