mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Address late review of venstar (#58813)
* Additional fixes from PR #58601 * Suggested fix to reduce attribute access
This commit is contained in:
parent
9daf2ee65d
commit
adfebaf510
@ -70,14 +70,13 @@ class VenstarDataUpdateCoordinator(update_coordinator.DataUpdateCoordinator):
|
|||||||
venstar_connection: VenstarColorTouch,
|
venstar_connection: VenstarColorTouch,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize global Venstar data updater."""
|
"""Initialize global Venstar data updater."""
|
||||||
self.client = venstar_connection
|
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
hass,
|
hass,
|
||||||
_LOGGER,
|
_LOGGER,
|
||||||
name=DOMAIN,
|
name=DOMAIN,
|
||||||
update_interval=timedelta(seconds=60),
|
update_interval=timedelta(seconds=60),
|
||||||
)
|
)
|
||||||
|
self.client = venstar_connection
|
||||||
|
|
||||||
async def _async_update_data(self) -> None:
|
async def _async_update_data(self) -> None:
|
||||||
"""Update the state."""
|
"""Update the state."""
|
||||||
@ -103,6 +102,8 @@ class VenstarDataUpdateCoordinator(update_coordinator.DataUpdateCoordinator):
|
|||||||
class VenstarEntity(CoordinatorEntity):
|
class VenstarEntity(CoordinatorEntity):
|
||||||
"""Representation of a Venstar entity."""
|
"""Representation of a Venstar entity."""
|
||||||
|
|
||||||
|
coordinator: VenstarDataUpdateCoordinator
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
venstar_data_coordinator: VenstarDataUpdateCoordinator,
|
venstar_data_coordinator: VenstarDataUpdateCoordinator,
|
||||||
@ -111,22 +112,11 @@ class VenstarEntity(CoordinatorEntity):
|
|||||||
"""Initialize the data object."""
|
"""Initialize the data object."""
|
||||||
super().__init__(venstar_data_coordinator)
|
super().__init__(venstar_data_coordinator)
|
||||||
self._config = config
|
self._config = config
|
||||||
self._update_attr()
|
self._client = venstar_data_coordinator.client
|
||||||
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."""
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _handle_coordinator_update(self) -> None:
|
def _handle_coordinator_update(self) -> None:
|
||||||
"""Handle updated data from the coordinator."""
|
"""Handle updated data from the coordinator."""
|
||||||
self._update_attr()
|
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
"""Support for Venstar WiFi Thermostats."""
|
"""Support for Venstar WiFi Thermostats."""
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
|
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity
|
||||||
@ -276,12 +274,7 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
|||||||
_LOGGER.error("Failed to change the operation mode")
|
_LOGGER.error("Failed to change the operation mode")
|
||||||
return success
|
return success
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs):
|
def 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):
|
|
||||||
"""Set a new target temperature."""
|
"""Set a new target temperature."""
|
||||||
set_temp = True
|
set_temp = True
|
||||||
operation_mode = kwargs.get(ATTR_HVAC_MODE)
|
operation_mode = kwargs.get(ATTR_HVAC_MODE)
|
||||||
@ -318,13 +311,9 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
|||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
_LOGGER.error("Failed to change the temperature")
|
_LOGGER.error("Failed to change the temperature")
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_set_fan_mode(self, fan_mode: str) -> None:
|
def set_fan_mode(self, fan_mode):
|
||||||
"""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):
|
|
||||||
"""Set new target fan mode."""
|
"""Set new target fan mode."""
|
||||||
if fan_mode == STATE_ON:
|
if fan_mode == STATE_ON:
|
||||||
success = self._client.set_fan(self._client.FAN_ON)
|
success = self._client.set_fan(self._client.FAN_ON)
|
||||||
@ -333,34 +322,22 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
|||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
_LOGGER.error("Failed to change the fan mode")
|
_LOGGER.error("Failed to change the fan mode")
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
|
def set_hvac_mode(self, hvac_mode):
|
||||||
"""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):
|
|
||||||
"""Set new target operation mode."""
|
"""Set new target operation mode."""
|
||||||
self._set_operation_mode(hvac_mode)
|
self._set_operation_mode(hvac_mode)
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
|
||||||
async def async_set_humidity(self, humidity: int) -> None:
|
def set_humidity(self, humidity):
|
||||||
"""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):
|
|
||||||
"""Set new target humidity."""
|
"""Set new target humidity."""
|
||||||
success = self._client.set_hum_setpoint(humidity)
|
success = self._client.set_hum_setpoint(humidity)
|
||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
_LOGGER.error("Failed to change the target humidity level")
|
_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:
|
def set_preset_mode(self, preset_mode):
|
||||||
"""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):
|
|
||||||
"""Set the hold mode."""
|
"""Set the hold mode."""
|
||||||
if preset_mode == PRESET_AWAY:
|
if preset_mode == PRESET_AWAY:
|
||||||
success = self._client.set_away(self._client.AWAY_AWAY)
|
success = self._client.set_away(self._client.AWAY_AWAY)
|
||||||
@ -376,3 +353,4 @@ class VenstarThermostat(VenstarEntity, ClimateEntity):
|
|||||||
|
|
||||||
if not success:
|
if not success:
|
||||||
_LOGGER.error("Failed to change the schedule/hold state")
|
_LOGGER.error("Failed to change the schedule/hold state")
|
||||||
|
self.schedule_update_ha_state()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user