Skip to content

Commit

Permalink
Bug fixed on load
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmarlor committed Dec 7, 2022
1 parent 4f32857 commit 928f959
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions custom_components/foxess_em/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
hass.data[DOMAIN][entry.entry_id]["unload"] = entry.add_update_listener(
async_reload_entry
)

return True


Expand Down
8 changes: 5 additions & 3 deletions custom_components/foxess_em/average/average_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ def __init__(
house_power: str,
aux_power: list[str],
) -> None:
UnloadController.__init__(self)
CallbackController.__init__(self)
HassLoadController.__init__(self, hass, self.async_refresh)
self._hass = hass
self._last_update = None

Expand All @@ -47,6 +44,11 @@ def __init__(

self._model = AverageModel(hass, entities, eco_start_time, eco_end_time)

# Setup mixins
UnloadController.__init__(self)
CallbackController.__init__(self)
HassLoadController.__init__(self, hass, self.async_refresh)

# Refresh every hour on the half hour
midnight_refresh = async_track_utc_time_change(
self._hass,
Expand Down
8 changes: 5 additions & 3 deletions custom_components/foxess_em/battery/battery_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ def __init__(
schedule: Schedule,
peak_utils: PeakPeriodUtils,
) -> None:
UnloadController.__init__(self)
CallbackController.__init__(self)
HassLoadController.__init__(self, hass, self.async_refresh)
self._hass = hass
self._schedule = schedule
self._peak_utils = peak_utils
Expand All @@ -60,6 +57,11 @@ def __init__(
self._average_controller = average_controller
self._last_update = None

# Setup mixins
UnloadController.__init__(self)
CallbackController.__init__(self)
HassLoadController.__init__(self, hass, self.async_refresh)

# Refresh on SoC change
battery_refresh = async_track_state_change(
self._hass, battery_soc, self.refresh
Expand Down
8 changes: 5 additions & 3 deletions custom_components/foxess_em/battery/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ class Schedule(HassLoadController, UnloadController):

def __init__(self, hass: HomeAssistant) -> None:
"""Get persisted schedule from states"""
UnloadController.__init__(self)
HassLoadController.__init__(self, hass, self.load)
self._hass = hass
self._schedule = {}

# Setup mixins
UnloadController.__init__(self)
HassLoadController.__init__(self, hass, self.load)

# Housekeeping on schedule
housekeeping = async_track_utc_time_change(
self._hass,
Expand All @@ -34,7 +36,7 @@ def __init__(self, hass: HomeAssistant) -> None:
)
self._unload_listeners.append(housekeeping)

def load(self, *args) -> None:
async def load(self, *args) -> None:
"""Load schedule from state"""
schedule = self._hass.states.get(_SCHEDULE)

Expand Down
2 changes: 1 addition & 1 deletion custom_components/foxess_em/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# Configuration and options
SOLCAST_API_KEY = "key"
SOLCAST_SCAN_INTERVAL = "scan_interval"
# SOLCAST_URL = "https://238beaac-50d9-4aa4-89eb-24f49d786205.mock.pstmn.io"
# SOLCAST_URL = "https://06db0776-e926-42bb-a6a2-85f88da8b0c8.mock.pstmn.io"
SOLCAST_URL = "https://api.solcast.com.au"
FOX_USERNAME = "fox_username"
FOX_PASSWORD = "fox_password"
Expand Down
8 changes: 5 additions & 3 deletions custom_components/foxess_em/forecast/forecast_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ class ForecastController(UnloadController, CallbackController, HassLoadControlle
"""Class to manage forecast retrieval"""

def __init__(self, hass: HomeAssistant, api: SolcastApiClient) -> None:
UnloadController.__init__(self)
CallbackController.__init__(self)
HassLoadController.__init__(self, hass, self.async_refresh)
self._hass = hass
self._api = ForecastModel(api)
self._api_count = 0
self._last_update = None

# Setup mixins
UnloadController.__init__(self)
CallbackController.__init__(self)
HassLoadController.__init__(self, hass, self.async_refresh)

async_call_later(hass, 5, self.setup_refresh)

async def setup_refresh(self, *args):
Expand Down

0 comments on commit 928f959

Please sign in to comment.