From d9adb0eea0ba3e378252d6c0881a32afcc61a53e Mon Sep 17 00:00:00 2001 From: steve Date: Thu, 3 Aug 2023 20:13:49 +1000 Subject: [PATCH] add feed cycle timer --- custom_components/apex/const.py | 6 ++++++ custom_components/apex/sensor.py | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/custom_components/apex/const.py b/custom_components/apex/const.py index 2c075db..874ae5e 100644 --- a/custom_components/apex/const.py +++ b/custom_components/apex/const.py @@ -21,6 +21,7 @@ {"did": "4", "name": "Feed D", "type": "Feed"} ] + SENSORS = { "Temp": {"icon": "mdi:water-thermometer", "measurement": "°C"}, "Cond": {"icon": "mdi:shaker-outline", "measurement": "ppt"}, @@ -38,8 +39,13 @@ "iotaPump|Sicce|Syncra": {"icon" : "mdi:pump", "measurement": "%"}, "variable" : {"icon" : "mdi:cog-outline"}, "virtual" : {"icon" : "mdi:cog-outline"}, + "feed" : {"icon": "mdi:timer", "measurement": "mins"} } +MANUAL_SENSORS = [ + {"name": "Feed Cycle Countdown", "type": "feed", "did": "feed_countdown"} +] + MEASUREMENTS = { "Celcius" : "°C", "Faren": "°F" diff --git a/custom_components/apex/sensor.py b/custom_components/apex/sensor.py index 0fe7b3d..ee8b4cf 100644 --- a/custom_components/apex/sensor.py +++ b/custom_components/apex/sensor.py @@ -4,7 +4,7 @@ from homeassistant.helpers.entity import Entity from . import ApexEntity -from .const import DOMAIN, SENSORS, MEASUREMENTS +from .const import DOMAIN, SENSORS, MEASUREMENTS, MANUAL_SENSORS _LOGGER = logging.getLogger(__name__) @@ -20,6 +20,12 @@ async def async_setup_entry(hass, config_entry, async_add_entities): if value["type"] == "dos" or value["type"] == "variable" or value["type"] == "virtual" or value["type"] == "iotaPump|Sicce|Syncra": sensor = ApexSensor(entry, value, config_entry.options) async_add_entities([sensor], True) + + + """Add Feed Status Remaining Time""" + for value in MANUAL_SENSORS: + sensor = ApexSensor(entry, value, config_entry.options) + async_add_entities([sensor], True) class ApexSensor( @@ -39,6 +45,11 @@ def __init__(self, coordinator, sensor, options): # Need to tidy this section up and avoid using so many for loops def get_value(self, ftype): if ftype == "state": + if self.sensor["type"] == "feed": + if self.coordinator.data["feed"]["active"] > 50000: + return 0 + else: + return round(self.coordinator.data["feed"]["active"] / 60, 1) for value in self.coordinator.data["inputs"]: if value["did"] == self.sensor["did"]: return value["value"]