Skip to content

Commit

Permalink
fix ina219 in OLED screen
Browse files Browse the repository at this point in the history
  • Loading branch information
pszafer committed Oct 4, 2024
1 parent a3e5f62 commit febf434
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
14 changes: 8 additions & 6 deletions boneio/helper/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,15 @@ def __init__(
},
}
if ina219 is not None:

def get_ina_values():
return {
sensor.device_class: f"{sensor.state} {sensor.unit_of_measurement}"
for sensor in ina219.sensors.values()
}

host_stats[INA219] = {
"f": lambda: {
*{
sensor.device_class: sensor.state
for sensor in ina219.sensors.values()
}
},
"f": get_ina_values,
"update_interval": TimePeriod(seconds=60),
}
self._data = {}
Expand Down
6 changes: 6 additions & 0 deletions boneio/schema/schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,12 @@ binary_sensor:
required: True
meta:
label: Check if sensor type is inverted. Only aplicable for sensor kind.
initial_send:
type: boolean
default: False
required: True
meta:
label: If set to true, then on startup of application initial status of the binary sensor will be send to MQTT.
device_class:
type: string
required: False
Expand Down
18 changes: 7 additions & 11 deletions boneio/sensor/ina219.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def update(self, time: datetime) -> None:
)


class INA219(AsyncUpdater, Filter):
class INA219(AsyncUpdater):
"""Represent INA219 sensors."""

def __init__(
Expand All @@ -77,16 +77,14 @@ def __init__(
self._loop = asyncio.get_event_loop()
self._ina_219 = INA219_I2C(address=address)
self._sensors = {}
self._states = {}
self._id = id
for sensor in sensors:
_name = sensor["id"]
_id = f"{id}{_name.replace(' ', '')}"
self._states[sensor["device_class"]] = None
self._sensors[sensor["device_class"]] = INA219Sensor(
device_class=sensor["device_class"],
filters=sensor.get("filters", []),
state=self._states[sensor["device_class"]],
state=None,
name=_name,
id=_id,
**kwargs,
Expand All @@ -104,11 +102,9 @@ def sensors(self) -> dict:

async def async_update(self, time: datetime) -> None:
"""Fetch temperature periodically and send to MQTT."""
for k in self._states.keys():
value = getattr(self._ina_219, k)
self._states[k] = value
_LOGGER.debug("Read %s with value: %s", k, value)
for k, sensor in self._sensors.items():
if sensor.raw_state != self._states[k]:
sensor.raw_state = self._states[k]
self._loop.call_soon_threadsafe(sensor.update, time)
value = getattr(self._ina_219, k)
_LOGGER.debug("Fetched INA219 value: %s %s", k, value)
if sensor.raw_state != value:
sensor.raw_state = value
sensor.update(time=time)

0 comments on commit febf434

Please sign in to comment.