Skip to content

Commit

Permalink
Se comprueba la diferencia máxima
Browse files Browse the repository at this point in the history
  • Loading branch information
MiguelAngelLV committed May 31, 2023
1 parent 742ddd8 commit 8dbb1cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion custom_components/balance_neto/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Constants for Balance Neto."""

DOMAIN = "balance_neto"
MAX_DIFF = 10.0
MAX_DIFF = 100.0
11 changes: 8 additions & 3 deletions custom_components/balance_neto/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ async def first_after_reboot(now):
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STARTED, first_after_reboot)




class GridSensor(SensorEntity, RestoreEntity):

def __init__(self, description: SensorEntityDescription, ) -> None:
super().__init__()
self._state = 0
Expand Down Expand Up @@ -182,6 +179,10 @@ def update_import(self, state: State | None):
if self._import_offset == 0:
self._import_offset = value

diff = abs(value - self._import_offset)
if diff > MAX_DIFF:
self._import_offset = value

self._import = value

self._update_value()
Expand All @@ -195,6 +196,10 @@ def update_export(self, state: State | None):
if self._export_offset == 0:
self._export_offset = value

diff = abs(value - self._export_offset)
if diff > MAX_DIFF:
self._export_offset = value

self._export = value
self._update_value()

Expand Down

0 comments on commit 8dbb1cd

Please sign in to comment.