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:
Greg Dowling 2020-07-10 16:42:27 +01:00 committed by GitHub
parent c260b7fa16
commit 405c1cdc86
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)