Remove unnecessary awaits in RainMachine (#32884)

* Remove unnecessary awaits in RainMachine

* Cleanup
This commit is contained in:
Aaron Bach 2020-03-17 05:00:54 -06:00 committed by GitHub
parent abd1909e2b
commit 0c49c8578b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 17 deletions

View file

@ -1,6 +1,7 @@
"""This platform provides support for sensor data from RainMachine."""
import logging
from homeassistant.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from . import RainMachineEntity
@ -146,9 +147,15 @@ class RainMachineSensor(RainMachineEntity):
async_dispatcher_connect(self.hass, SENSOR_UPDATE_TOPIC, self._update_state)
)
await self.rainmachine.async_register_sensor_api_interest(self._api_category)
await self.async_update()
self.update_from_latest_data()
async def async_update(self):
async def async_will_remove_from_hass(self):
"""Disconnect dispatcher listeners and deregister API interest."""
super().async_will_remove_from_hass()
self.rainmachine.async_deregister_sensor_api_interest(self._api_category)
@callback
def update_from_latest_data(self):
"""Update the sensor's state."""
if self._sensor_type == TYPE_FLOW_SENSOR_CLICK_M3:
self._state = self.rainmachine.data[DATA_PROVISION_SETTINGS]["system"].get(
@ -178,8 +185,3 @@ class RainMachineSensor(RainMachineEntity):
self._state = self.rainmachine.data[DATA_RESTRICTIONS_UNIVERSAL][
"freezeProtectTemp"
]
async def async_will_remove_from_hass(self):
"""Disconnect dispatcher listeners and deregister API interest."""
super().async_will_remove_from_hass()
self.rainmachine.async_deregister_sensor_api_interest(self._api_category)