Skip to content

Commit

Permalink
Merge pull request #30 from Crewski/coveredSensor
Browse files Browse the repository at this point in the history
Fix cover to be a binary sensor
  • Loading branch information
Crewski authored May 16, 2023
2 parents ee43682 + 347efc8 commit 7cd9a72
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
9 changes: 8 additions & 1 deletion custom_components/njspc_ha/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .controller import FreezeProtectionSensor
from .pumps import PumpOnSensor
from .bodies import FilterOnSensor
from .bodies import FilterOnSensor, BodyCoveredSensor
from .features import VirtualCircuit

from .const import (
Expand Down Expand Up @@ -45,5 +45,12 @@ async def async_setup_entry(
)
)

if "bodies" in config["temps"]: # We can have Nobody Nixie systems (equipment only)
for body in list(config["temps"]["bodies"]):
if "isCovered" in body:
new_devices.append(
BodyCoveredSensor(coordinator=coordinator, body=body)
)

if new_devices:
async_add_entities(new_devices)
8 changes: 7 additions & 1 deletion custom_components/njspc_ha/bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
)
from homeassistant.components.binary_sensor import (
BinarySensorEntity,
BinarySensorDeviceClass
)

from .entity import PoolEquipmentEntity
Expand Down Expand Up @@ -738,10 +739,15 @@ def unique_id(self) -> str | None:
@property
def is_on(self) -> bool:
"""Return if the body is covered."""
return self._value
# we want the opposite of the isCovered field
return not self._value

@property
def icon(self) -> str:
if self._value is True:
return "mdi:arrow-down-drop-circle"
return "mdi:arrow-up-drop-circle-outline"

@property
def device_class(self) -> BinarySensorDeviceClass | None:
return BinarySensorDeviceClass.DOOR
4 changes: 0 additions & 4 deletions custom_components/njspc_ha/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ async def async_setup_entry(
new_devices.append(
BodyTempSensor(coordinator=coordinator, units=units, body=body)
)
if "isCovered" in body:
new_devices.append(
BodyCoveredSensor(coordinator=coordinator, body=body)
)

for pump in config["pumps"]:
# Pump sensors vary by type. This may need a re-visit for pump types that use a
Expand Down

0 comments on commit 7cd9a72

Please sign in to comment.