1 """Support for LiteJet switch."""
5 from pylitejet
import LiteJet, LiteJetError
14 from .const
import DOMAIN
16 ATTR_NUMBER =
"number"
21 config_entry: ConfigEntry,
22 async_add_entities: AddEntitiesCallback,
26 system: LiteJet = hass.data[DOMAIN]
29 for i
in system.button_switches():
30 name = await system.get_switch_name(i)
31 entities.append(
LiteJetSwitch(config_entry.entry_id, system, i, name))
37 """Representation of a single LiteJet switch."""
39 _attr_should_poll =
False
40 _attr_has_entity_name =
True
41 _attr_entity_registry_enabled_default =
False
42 _attr_device_class = SwitchDeviceClass.SWITCH
44 def __init__(self, entry_id: str, system: LiteJet, i: int, name: str) ->
None:
45 """Initialize a LiteJet switch."""
53 keypad_number = system.get_switch_keypad_number(i)
55 identifiers={(DOMAIN, f
"{entry_id}_keypad_{keypad_number}")},
56 name=system.get_switch_keypad_name(i),
57 manufacturer=
"Centralite",
58 via_device=(DOMAIN, f
"{entry_id}_mcp"),
62 """Run when this Entity has been added to HA."""
68 """Entity being removed from hass."""
87 """Return the device-specific state attributes."""
88 return {ATTR_NUMBER: self.
_index_index}
91 """Press the switch."""
93 await self.
_lj_lj.press_switch(self.
_index_index)
94 except LiteJetError
as exc:
95 raise HomeAssistantError
from exc
98 """Release the switch."""
100 await self.
_lj_lj.release_switch(self.
_index_index)
101 except LiteJetError
as exc:
102 raise HomeAssistantError
from exc
dict[str, Any] extra_state_attributes(self)
None async_turn_on(self, **Any kwargs)
None _on_switch_released(self)
None async_turn_off(self, **Any kwargs)
None _on_switch_pressed(self)
None async_added_to_hass(self)
None async_will_remove_from_hass(self)
None _on_connected_changed(self, bool connected, str reason)
None __init__(self, str entry_id, LiteJet system, int i, str name)
None async_write_ha_state(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)