Skip to content

Commit

Permalink
add feed cycle timer
Browse files Browse the repository at this point in the history
  • Loading branch information
itchannel committed Aug 3, 2023
1 parent 3cb18a7 commit d9adb0e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions custom_components/apex/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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"
Expand Down
13 changes: 12 additions & 1 deletion custom_components/apex/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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(
Expand All @@ -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"]
Expand Down

0 comments on commit d9adb0e

Please sign in to comment.