mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Fix loopenergy callback updating HA before the object is initialised (#37650)
* Fix loopenergy callback updating HA before the object is initialised. * Change to use async_added_to_hass.
This commit is contained in:
parent
c260b7fa16
commit
405c1cdc86
@ -123,10 +123,13 @@ class LoopEnergyElec(LoopEnergyDevice):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(controller)
|
||||
self._name = "Power Usage"
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self._controller.subscribe_elecricity(self._callback)
|
||||
|
||||
def update(self):
|
||||
"""Get the cached Loop energy."""
|
||||
"""Get the cached Loop energy reading."""
|
||||
self._state = round(self._controller.electricity_useage, 2)
|
||||
|
||||
|
||||
@ -137,8 +140,11 @@ class LoopEnergyGas(LoopEnergyDevice):
|
||||
"""Initialize the sensor."""
|
||||
super().__init__(controller)
|
||||
self._name = "Gas Usage"
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Subscribe to updates."""
|
||||
self._controller.subscribe_gas(self._callback)
|
||||
|
||||
def update(self):
|
||||
"""Get the cached Loop energy."""
|
||||
"""Get the cached Loop gas reading."""
|
||||
self._state = round(self._controller.gas_useage, 2)
|
||||
|
Loading…
x
Reference in New Issue
Block a user