1 """Platform for Omnilogic switch integration."""
6 from omnilogic
import OmniLogicException
7 import voluptuous
as vol
15 from .common
import check_guard
16 from .const
import COORDINATOR, DOMAIN, PUMP_TYPES
17 from .coordinator
import OmniLogicUpdateCoordinator
18 from .entity
import OmniLogicEntity
20 SERVICE_SET_SPEED =
"set_pump_speed"
21 OMNILOGIC_SWITCH_OFF = 7
25 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
27 """Set up the light platform."""
29 coordinator: OmniLogicUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][
34 for item_id, item
in coordinator.data.items():
36 item_kind = item_id[-2]
37 entity_settings = SWITCH_TYPES.get((id_len, item_kind))
39 if not entity_settings:
42 for entity_setting
in entity_settings:
43 entity_classes: dict[str, type] = entity_setting[
"entity_classes"]
44 for state_key, entity_class
in entity_classes.items():
48 entity = entity_class(
49 coordinator=coordinator,
51 name=entity_setting[
"name"],
52 kind=entity_setting[
"kind"],
54 icon=entity_setting[
"icon"],
57 entities.append(entity)
62 platform = entity_platform.async_get_current_platform()
64 platform.async_register_entity_service(
66 {vol.Required(
"speed"): cv.positive_int},
72 """Define an Omnilogic Base Switch entity to be extended."""
76 coordinator: OmniLogicUpdateCoordinator,
83 """Initialize Entities."""
85 coordinator=coordinator,
99 """Return the on/off state of the switch."""
109 if self.
_state_state == OMNILOGIC_SWITCH_OFF:
112 self.
_state_state = state_int != 0
118 """Define the OmniLogic Relay entity."""
121 """Turn on the relay."""
126 await self.coordinator.api.set_relay_valve(
134 """Turn off the relay."""
139 await self.coordinator.api.set_relay_valve(
148 """Define the OmniLogic Pump Switch Entity."""
152 coordinator: OmniLogicUpdateCoordinator,
159 """Initialize entities."""
161 coordinator=coordinator,
172 if "Filter-Type" in coordinator.data[item_id]:
173 self.
_pump_type_pump_type = PUMP_TYPES[coordinator.data[item_id][
"Filter-Type"]]
175 self.
_pump_type_pump_type = PUMP_TYPES[coordinator.data[item_id][
"Type"]]
180 """Turn on the pump."""
190 await self.coordinator.api.set_relay_valve(
198 """Turn off the pump."""
204 if "filterSpeed" in self.coordinator.data[self.
_item_id_item_id]:
209 await self.coordinator.api.set_relay_valve(
217 """Set the switch speed."""
221 success = await self.coordinator.api.set_relay_valve(
232 raise OmniLogicException(
233 "Cannot set speed. Speed is outside pump range."
237 raise OmniLogicException(
"Cannot set speed on a non-variable speed pump.")
240 SWITCH_TYPES: dict[tuple[int, str], list[dict[str, Any]]] = {
243 "entity_classes": {
"switchState": OmniLogicRelayControl},
247 "guard_condition": [],
252 "entity_classes": {
"switchState": OmniLogicRelayControl},
256 "guard_condition": [],
261 "entity_classes": {
"pumpState": OmniLogicPumpControl},
265 "guard_condition": [],
270 "entity_classes": {
"filterState": OmniLogicPumpControl},
274 "guard_condition": [],
None __init__(self, OmniLogicUpdateCoordinator coordinator, str kind, str name, str icon, tuple item_id, str state_key)
def async_turn_on(self, **kwargs)
def async_turn_off(self, **kwargs)
def async_set_speed(self, speed)
def async_turn_off(self, **kwargs)
def async_turn_on(self, **kwargs)
None __init__(self, OmniLogicUpdateCoordinator coordinator, str kind, str name, str icon, tuple item_id, str state_key)
None async_write_ha_state(self)
web.Response get(self, web.Request request, str config_key)
def check_guard(state_key, item, entity_setting)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)