Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix STATIC planner #55

Merged
merged 17 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
This could actually be working
  • Loading branch information
dala318 committed Dec 20, 2024
commit 3e2d896707e16ef28f1a0849fde3a3496e5ae0a8
11 changes: 7 additions & 4 deletions custom_components/nordpool_planner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None:

# Local state variables
self._last_update = None
self.low_hours = None

# Output states
self.low_cost_state = NordpoolPlannerState()
Expand Down Expand Up @@ -515,10 +516,12 @@ def update(self):
)
if self._is_static:
if self.low_cost_state.on_at(now):
if counter := self._output_listeners.get(
CONF_REMAINING_HOURS_ENTITY
):
pass
if self.low_hours is None:
self.low_hours = 1
else:
self.low_hours += 1
if end_time.hour == now.hour:
self.low_hours = 0
self._last_update = now

def set_lowest_cost_state(self, prices_group: NordpoolPricesGroup) -> None:
Expand Down
20 changes: 6 additions & 14 deletions custom_components/nordpool_planner/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,16 @@ async def async_added_to_hass(self) -> None:
await super().async_added_to_hass()
if (
(last_state := await self.async_get_last_state()) is not None
and (extra_data := await self.async_get_last_sensor_data()) is not None
and last_state.state not in (STATE_UNKNOWN, STATE_UNAVAILABLE)
# The trigger might have fired already while we waited for stored data,
# then we should not restore state

# and CONF_STATE not in self._rendered
# and (extra_data := await self.async_get_last_sensor_data()) is not None
):
# self._rendered[CONF_STATE] = extra_data.native_value
self.restore_attributes(last_state)

# ToDo: Call planner and set value there!
self._planner.low_hours = last_state.state
else:
# self._planner.low_hours = 0
pass


@property
def native_value(self):
"""Output state."""
state = None

# TODO: Add the logic

return state
return self._planner.low_hours