From adfebaf51054f13a9f10eb0e352bd26899c860c0 Mon Sep 17 00:00:00 2001 From: Tim Rightnour <6556271+garbled1@users.noreply.github.com> Date: Sun, 31 Oct 2021 15:25:19 -0700 Subject: [PATCH] Address late review of venstar (#58813) * Additional fixes from PR #58601 * Suggested fix to reduce attribute access --- homeassistant/components/venstar/__init__.py | 18 ++------- homeassistant/components/venstar/climate.py | 42 +++++--------------- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/homeassistant/components/venstar/__init__.py b/homeassistant/components/venstar/__init__.py index 5f2aabe6738..69bc1bf188c 100644 --- a/homeassistant/components/venstar/__init__.py +++ b/homeassistant/components/venstar/__init__.py @@ -70,14 +70,13 @@ class VenstarDataUpdateCoordinator(update_coordinator.DataUpdateCoordinator): venstar_connection: VenstarColorTouch, ) -> None: """Initialize global Venstar data updater.""" - self.client = venstar_connection - super().__init__( hass, _LOGGER, name=DOMAIN, update_interval=timedelta(seconds=60), ) + self.client = venstar_connection async def _async_update_data(self) -> None: """Update the state.""" @@ -103,6 +102,8 @@ class VenstarDataUpdateCoordinator(update_coordinator.DataUpdateCoordinator): class VenstarEntity(CoordinatorEntity): """Representation of a Venstar entity.""" + coordinator: VenstarDataUpdateCoordinator + def __init__( self, venstar_data_coordinator: VenstarDataUpdateCoordinator, @@ -111,22 +112,11 @@ class VenstarEntity(CoordinatorEntity): """Initialize the data object.""" super().__init__(venstar_data_coordinator) self._config = config - self._update_attr() - self.coordinator = venstar_data_coordinator - - @property - def _client(self): - """Return the venstar client.""" - return self.coordinator.client - - @callback - def _update_attr(self) -> None: - """Update the state and attributes.""" + self._client = venstar_data_coordinator.client @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" - self._update_attr() self.async_write_ha_state() @property diff --git a/homeassistant/components/venstar/climate.py b/homeassistant/components/venstar/climate.py index c53cc9685e2..5d28d41db53 100644 --- a/homeassistant/components/venstar/climate.py +++ b/homeassistant/components/venstar/climate.py @@ -1,6 +1,4 @@ """Support for Venstar WiFi Thermostats.""" -from functools import partial - import voluptuous as vol from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity @@ -276,12 +274,7 @@ class VenstarThermostat(VenstarEntity, ClimateEntity): _LOGGER.error("Failed to change the operation mode") return success - async def async_set_temperature(self, **kwargs): - """Set a new target temperature.""" - await self.hass.async_add_executor_job(partial(self._set_temperature, **kwargs)) - self.async_write_ha_state() - - def _set_temperature(self, **kwargs): + def set_temperature(self, **kwargs): """Set a new target temperature.""" set_temp = True operation_mode = kwargs.get(ATTR_HVAC_MODE) @@ -318,13 +311,9 @@ class VenstarThermostat(VenstarEntity, ClimateEntity): if not success: _LOGGER.error("Failed to change the temperature") + self.schedule_update_ha_state() - async def async_set_fan_mode(self, fan_mode: str) -> None: - """Set a new target fan mode.""" - await self.hass.async_add_executor_job(self._set_fan_mode, fan_mode) - self.async_write_ha_state() - - def _set_fan_mode(self, fan_mode): + def set_fan_mode(self, fan_mode): """Set new target fan mode.""" if fan_mode == STATE_ON: success = self._client.set_fan(self._client.FAN_ON) @@ -333,34 +322,22 @@ class VenstarThermostat(VenstarEntity, ClimateEntity): if not success: _LOGGER.error("Failed to change the fan mode") + self.schedule_update_ha_state() - async def async_set_hvac_mode(self, hvac_mode: str) -> None: - """Set a new target operation mode.""" - await self.hass.async_add_executor_job(self._set_hvac_mode, hvac_mode) - self.async_write_ha_state() - - def _set_hvac_mode(self, hvac_mode): + def set_hvac_mode(self, hvac_mode): """Set new target operation mode.""" self._set_operation_mode(hvac_mode) + self.schedule_update_ha_state() - async def async_set_humidity(self, humidity: int) -> None: - """Set a new target humidity.""" - await self.hass.async_add_executor_job(self._set_humidity, humidity) - self.async_write_ha_state() - - def _set_humidity(self, humidity): + def set_humidity(self, humidity): """Set new target humidity.""" success = self._client.set_hum_setpoint(humidity) if not success: _LOGGER.error("Failed to change the target humidity level") + self.schedule_update_ha_state() - async def async_set_preset_mode(self, preset_mode: str) -> None: - """Set the hold mode.""" - await self.hass.async_add_executor_job(self._set_preset_mode, preset_mode) - self.async_write_ha_state() - - def _set_preset_mode(self, preset_mode): + def set_preset_mode(self, preset_mode): """Set the hold mode.""" if preset_mode == PRESET_AWAY: success = self._client.set_away(self._client.AWAY_AWAY) @@ -376,3 +353,4 @@ class VenstarThermostat(VenstarEntity, ClimateEntity): if not success: _LOGGER.error("Failed to change the schedule/hold state") + self.schedule_update_ha_state()