Skip to content

Commit

Permalink
Merge pull request #35 from Crewski/pump-relay
Browse files Browse the repository at this point in the history
Add support for hayward vs relay pump
  • Loading branch information
Crewski authored Jul 6, 2023
2 parents e613daf + 8adde9e commit 14a3ae0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
62 changes: 62 additions & 0 deletions custom_components/njspc_ha/pumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,68 @@
PoolEquipmentClass,
)

class PumpProgramSensor(PoolEquipmentEntity, SensorEntity):
"""Program Pump Sensor for njsPC-HA"""

def __init__(self, coordinator: NjsPCHAdata, pump: Any) -> None:
"""Initialize the sensor."""
super().__init__(
coordinator=coordinator,
equipment_class=PoolEquipmentClass.PUMP,
data=pump,
)
self._value = None
if "command" in pump:
self._value = pump["command"]
self._available = True
self._attr_device_class = f"{self.equipment_name}_{self.equipment_class}_program"

def _handle_coordinator_update(self) -> None:
"""Handle updated data from the coordinator."""
if (
self.coordinator.data["event"] == EVENT_PUMP
and self.coordinator.data["id"] == self.equipment_id
and "command" in self.coordinator.data
):
if "command" in self.coordinator.data:
self._available = True
self._value = f'Program #{self.coordinator.data["command"]}'
else:
self._available = False
self._value = None
self.async_write_ha_state()
elif self.coordinator.data["event"] == EVENT_AVAILABILITY:
self._available = self.coordinator.data["available"]
self.async_write_ha_state()

@property
def should_poll(self) -> bool:
return False

@property
def available(self) -> bool:
return self._available

@property
def name(self) -> str:
"""Name of the sensor"""
return "Program"

@property
def unique_id(self) -> str:
"""ID of the sensor"""
return f"{self.coordinator.controller_id}_{self.equipment_class}_{self.equipment_id}_program"

@property
def native_value(self) -> int:
"""Raw value of the sensor"""
return self._value

@property
def icon(self) -> str:
return "mdi:speedometer"



class PumpSpeedSensor(PoolEquipmentEntity, SensorEntity):
"""RPM Pump Sensor for njsPC-HA"""
Expand Down
5 changes: 4 additions & 1 deletion custom_components/njspc_ha/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
TargetOutputSensor,
SaturationIndexSensor,
)
from .pumps import PumpPowerSensor, PumpFlowSensor, PumpSpeedSensor
from .pumps import PumpPowerSensor, PumpFlowSensor, PumpSpeedSensor, PumpProgramSensor
from .controller import PanelModeSensor, TempProbeSensor
from .bodies import BodyTempSensor, FilterPressureSensor, FilterCleanSensor, BodyCoveredSensor
from .const import (
Expand Down Expand Up @@ -92,6 +92,9 @@ async def async_setup_entry(
new_devices.append(PumpSpeedSensor(coordinator=coordinator, pump=pump))
if "maxFlow" in pump_type:
new_devices.append(PumpFlowSensor(coordinator=coordinator, pump=pump))
if "relays" in pump_type:
new_devices.append(PumpProgramSensor(coordinator=coordinator, pump=pump))

if "maxSpeed" in pump_type or "maxFlow" in pump_type:
new_devices.append(PumpPowerSensor(coordinator=coordinator, pump=pump))
if STATUS in pump:
Expand Down

0 comments on commit 14a3ae0

Please sign in to comment.