Skip to content

Commit

Permalink
remove on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Aug 1, 2021
1 parent 51b5044 commit 919e140
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions custom_components/erse/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@ async def async_increment_cost(event):
new_state = event.data.get("new_state")
calc_costs(new_state.state)

async_track_state_change_event(
self.hass, [self._meter_entity], async_increment_cost
self.async_on_remove(
async_track_state_change_event(
self.hass, [self._meter_entity], async_increment_cost
)
)

@callback
Expand Down Expand Up @@ -153,8 +155,11 @@ def __init__(self, operator, plan, meter, power_cost) -> None:

async def async_added_to_hass(self):
"""Setups all required entities and automations."""
async_track_time_change(
self.hass, self.timer_update, hour=[0], minute=[0], second=[0]

self.async_on_remove(
async_track_time_change(
self.hass, self.timer_update, hour=[0], minute=[0], second=[0]
)
)

@callback
Expand Down Expand Up @@ -199,7 +204,10 @@ def __init__(self, name, config):

async def async_added_to_hass(self):
"""Setups all required entities and automations."""
async_track_time_change(self.hass, self.timer_update, minute=range(0, 60, 15))

self.async_on_remove(
async_track_time_change(self.hass, self.timer_update, minute=range(0, 60, 15))
)

@callback
async def initial_sync(event):
Expand Down

0 comments on commit 919e140

Please sign in to comment.