From 405c1cdc868f054a3e04e00f6b35d1c955e94655 Mon Sep 17 00:00:00 2001 From: Greg Dowling Date: Fri, 10 Jul 2020 16:42:27 +0100 Subject: [PATCH] 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. --- homeassistant/components/loopenergy/sensor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/loopenergy/sensor.py b/homeassistant/components/loopenergy/sensor.py index 537907d9d0a..85494d354b5 100644 --- a/homeassistant/components/loopenergy/sensor.py +++ b/homeassistant/components/loopenergy/sensor.py @@ -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)