Skip to content

Commit

Permalink
v0.03
Browse files Browse the repository at this point in the history
bugfix update values
update timer 10 minutes
add hacs.json
  • Loading branch information
chises committed Apr 24, 2022
1 parent 0997cfb commit 4c04c60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 12 additions & 7 deletions custom_components/oilfox/sensor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""Platform for sensor integration."""

from __future__ import annotations
from datetime import timedelta
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

from homeassistant.components.sensor import (
SensorEntity,
Expand All @@ -13,10 +17,6 @@
TIME_DAYS
)

from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType

import requests
import logging
import time
Expand All @@ -28,6 +28,7 @@
DOMAIN = "OilFox_api"
CONF_EMAIL = "email"
CONF_PASSWORD = "password"
SCAN_INTERVAL = timedelta(minutes=10)

SENSORS = {
"fillLevelPercent": [
Expand Down Expand Up @@ -79,7 +80,7 @@ def setup_platform(
else:
_LOGGER.info("OilFox: Device "+item['hwid']+" missing sensor "+SENSORS[key][0])

add_entities(entities)
add_entities(entities, True)

class OilFoxSensor(SensorEntity):
OilFox = None
Expand All @@ -97,6 +98,11 @@ def icon(self) -> str:
"""Return the name of the sensor."""
return self.sensor[2]

@property
def unique_id(self) -> str:
"""Return the name of the sensor."""
return "OilFox-"+self.OilFox.hwid+"-"+self.sensor[0]

@property
def name(self) -> str:
"""Return the name of the sensor."""
Expand All @@ -115,7 +121,6 @@ def unit_of_measurement(self) -> str:
@property
def extra_state_attributes(self):
"""Return the attributes of the sensor."""
#additional_attributes={ }
additional_attributes={
"Last Measurement": self.OilFox.state.get("currentMeteringAt"),
"Next Measurement": self.OilFox.state.get("nextMeteringAt"),
Expand All @@ -124,7 +129,7 @@ def extra_state_attributes(self):
return additional_attributes

def update(self) -> None:
#self.OilFox.updateStats()
self.OilFox.updateStats()
if not self.OilFox.state == None and not self.OilFox.state.get(self.sensor[0]) == None:
self._state = self.OilFox.state.get(self.sensor[0])
else:
Expand Down
4 changes: 4 additions & 0 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "OilFox Sensor",
"render_readme": true
}

0 comments on commit 4c04c60

Please sign in to comment.