Fix rainforest eagle incorrectly fetch conncted first try (#55193)

This commit is contained in:
Paulus Schoutsen 2021-08-25 02:43:08 -07:00 committed by GitHub
parent bf1112bc10
commit 186b8d4f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,23 +136,28 @@ class EagleDataCoordinator(DataUpdateCoordinator):
async def _async_update_data_200(self):
"""Get the latest data from the Eagle-200 device."""
if self.eagle200_meter is None:
eagle200_meter = self.eagle200_meter
if eagle200_meter is None:
hub = aioeagle.EagleHub(
aiohttp_client.async_get_clientsession(self.hass),
self.cloud_id,
self.entry.data[CONF_INSTALL_CODE],
host=self.entry.data[CONF_HOST],
)
self.eagle200_meter = aioeagle.ElectricMeter.create_instance(
eagle200_meter = aioeagle.ElectricMeter.create_instance(
hub, self.hardware_address
)
is_connected = self.eagle200_meter.is_connected
is_connected = True
else:
is_connected = eagle200_meter.is_connected
async with async_timeout.timeout(30):
data = await self.eagle200_meter.get_device_query()
data = await eagle200_meter.get_device_query()
if is_connected and not self.eagle200_meter.is_connected:
if self.eagle200_meter is None:
self.eagle200_meter = eagle200_meter
elif is_connected and not eagle200_meter.is_connected:
_LOGGER.warning("Lost connection with electricity meter")
_LOGGER.debug("API data: %s", data)