1 """Platform for sensor integration."""
6 import voluptuous
as vol
15 from .const
import DOMAIN, SMARTTUB_CONTROLLER
16 from .entity
import SmartTubSensorBase
19 ATTR_DURATION =
"duration"
20 ATTR_CYCLE_LAST_UPDATED =
"cycle_last_updated"
23 ATTR_START_HOUR =
"start_hour"
25 SET_PRIMARY_FILTRATION_SCHEMA = vol.All(
26 cv.has_at_least_one_key(ATTR_DURATION, ATTR_START_HOUR),
27 cv.make_entity_service_schema(
29 vol.Optional(ATTR_DURATION): vol.All(int, vol.Range(min=1, max=24)),
30 vol.Optional(ATTR_START_HOUR): vol.All(int, vol.Range(min=0, max=23)),
35 SET_SECONDARY_FILTRATION_SCHEMA: VolDictType = {
36 vol.Required(ATTR_MODE): vol.In(
39 for mode
in smarttub.SpaSecondaryFiltrationCycle.SecondaryFiltrationMode
46 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
48 """Set up sensor entities for the sensors in the tub."""
50 controller = hass.data[DOMAIN][entry.entry_id][SMARTTUB_CONTROLLER]
53 for spa
in controller.spas:
58 controller.coordinator, spa,
"Flow Switch",
"flow_switch"
63 controller.coordinator, spa,
"Blowout Cycle",
"blowout_cycle"
66 controller.coordinator, spa,
"Cleanup Cycle",
"cleanup_cycle"
75 platform = entity_platform.async_get_current_platform()
77 platform.async_register_entity_service(
78 "set_primary_filtration",
79 SET_PRIMARY_FILTRATION_SCHEMA,
80 "async_set_primary_filtration",
83 platform.async_register_entity_service(
84 "set_secondary_filtration",
85 SET_SECONDARY_FILTRATION_SCHEMA,
86 "async_set_secondary_filtration",
91 """Generic class for SmartTub status sensors."""
95 """Return the current state of the sensor."""
96 if self.
_state_state
is None:
99 if isinstance(self.
_state_state, Enum):
100 return self.
_state_state.name.lower()
102 return self.
_state_state.lower()
106 """The primary filtration cycle."""
109 """Initialize the entity."""
111 coordinator, spa,
"Primary Filtration Cycle",
"primary_filtration"
115 def cycle(self) -> smarttub.SpaPrimaryFiltrationCycle:
116 """Return the underlying smarttub.SpaPrimaryFiltrationCycle object."""
121 """Return the current state of the sensor."""
122 return self.
cyclecycle.status.name.lower()
126 """Return the state attributes."""
128 ATTR_DURATION: self.
cyclecycle.duration,
129 ATTR_CYCLE_LAST_UPDATED: self.
cyclecycle.last_updated.isoformat(),
130 ATTR_MODE: self.
cyclecycle.mode.name.lower(),
131 ATTR_START_HOUR: self.
cyclecycle.start_hour,
135 """Update primary filtration settings."""
136 await self.
cyclecycle.set(
137 duration=kwargs.get(ATTR_DURATION),
138 start_hour=kwargs.get(ATTR_START_HOUR),
140 await self.coordinator.async_request_refresh()
144 """The secondary filtration cycle."""
147 """Initialize the entity."""
149 coordinator, spa,
"Secondary Filtration Cycle",
"secondary_filtration"
153 def cycle(self) -> smarttub.SpaSecondaryFiltrationCycle:
154 """Return the underlying smarttub.SpaSecondaryFiltrationCycle object."""
159 """Return the current state of the sensor."""
160 return self.
cyclecycle.status.name.lower()
164 """Return the state attributes."""
166 ATTR_CYCLE_LAST_UPDATED: self.
cyclecycle.last_updated.isoformat(),
167 ATTR_MODE: self.
cyclecycle.mode.name.lower(),
171 """Update primary filtration settings."""
172 mode = smarttub.SpaSecondaryFiltrationCycle.SecondaryFiltrationMode[
173 kwargs[ATTR_MODE].upper()
175 await self.
cyclecycle.set_mode(mode)
176 await self.coordinator.async_request_refresh()
def __init__(self, coordinator, spa)
def async_set_primary_filtration(self, **kwargs)
def extra_state_attributes(self)
smarttub.SpaPrimaryFiltrationCycle cycle(self)
smarttub.SpaSecondaryFiltrationCycle cycle(self)
def extra_state_attributes(self)
def __init__(self, coordinator, spa)
def async_set_secondary_filtration(self, **kwargs)
str|None native_value(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)