Update plugwise to async and config_flow sensor part (#36219)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
parent
5d7720832b
commit
d0fedad000
7 changed files with 439 additions and 83 deletions
|
@ -1,7 +1,6 @@
|
|||
"""Plugwise Climate component for Home Assistant."""
|
||||
|
||||
import logging
|
||||
from typing import Dict
|
||||
|
||||
from Plugwise_Smile.Smile import Smile
|
||||
|
||||
|
@ -17,16 +16,10 @@ from homeassistant.components.climate.const import (
|
|||
SUPPORT_TARGET_TEMPERATURE,
|
||||
)
|
||||
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS
|
||||
from homeassistant.core import callback
|
||||
|
||||
from . import SmileGateway
|
||||
from .const import (
|
||||
DEFAULT_MAX_TEMP,
|
||||
DEFAULT_MIN_TEMP,
|
||||
DOMAIN,
|
||||
SCHEDULE_OFF,
|
||||
SCHEDULE_ON,
|
||||
THERMOSTAT_ICON,
|
||||
)
|
||||
from .const import DEFAULT_MAX_TEMP, DEFAULT_MIN_TEMP, DOMAIN, SCHEDULE_OFF, SCHEDULE_ON
|
||||
|
||||
HVAC_MODES_HEAT_ONLY = [HVAC_MODE_HEAT, HVAC_MODE_AUTO]
|
||||
HVAC_MODES_HEAT_COOL = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO]
|
||||
|
@ -47,20 +40,20 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||
"zone_thermostat",
|
||||
"thermostatic_radiator_valve",
|
||||
]
|
||||
all_entities = api.get_all_devices()
|
||||
all_devices = api.get_all_devices()
|
||||
|
||||
for dev_id, device in all_entities.items():
|
||||
for dev_id, device_properties in all_devices.items():
|
||||
|
||||
if device["class"] not in thermostat_classes:
|
||||
if device_properties["class"] not in thermostat_classes:
|
||||
continue
|
||||
|
||||
thermostat = PwThermostat(
|
||||
api,
|
||||
coordinator,
|
||||
device["name"],
|
||||
device_properties["name"],
|
||||
dev_id,
|
||||
device["location"],
|
||||
device["class"],
|
||||
device_properties["location"],
|
||||
device_properties["class"],
|
||||
DEFAULT_MIN_TEMP,
|
||||
DEFAULT_MAX_TEMP,
|
||||
)
|
||||
|
@ -77,11 +70,9 @@ class PwThermostat(SmileGateway, ClimateEntity):
|
|||
self, api, coordinator, name, dev_id, loc_id, model, min_temp, max_temp
|
||||
):
|
||||
"""Set up the Plugwise API."""
|
||||
super().__init__(api, coordinator)
|
||||
super().__init__(api, coordinator, name, dev_id)
|
||||
|
||||
self._api = api
|
||||
self._name = name
|
||||
self._dev_id = dev_id
|
||||
self._loc_id = loc_id
|
||||
self._model = model
|
||||
self._min_temp = min_temp
|
||||
|
@ -92,9 +83,9 @@ class PwThermostat(SmileGateway, ClimateEntity):
|
|||
self._preset_mode = None
|
||||
self._presets = None
|
||||
self._presets_list = None
|
||||
self._boiler_state = None
|
||||
self._heating_state = None
|
||||
self._cooling_state = None
|
||||
self._compressor_state = None
|
||||
self._dhw_state = None
|
||||
self._hvac_mode = None
|
||||
self._schema_names = None
|
||||
|
@ -111,43 +102,16 @@ class PwThermostat(SmileGateway, ClimateEntity):
|
|||
def hvac_action(self):
|
||||
"""Return the current action."""
|
||||
if self._single_thermostat:
|
||||
if self._heating_state or self._boiler_state:
|
||||
if self._heating_state:
|
||||
return CURRENT_HVAC_HEAT
|
||||
if self._cooling_state:
|
||||
return CURRENT_HVAC_COOL
|
||||
return CURRENT_HVAC_IDLE
|
||||
if self._heating_state is not None or self._boiler_state is not None:
|
||||
if self._heating_state is not None:
|
||||
if self._setpoint > self._temperature:
|
||||
return CURRENT_HVAC_HEAT
|
||||
return CURRENT_HVAC_IDLE
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the thermostat, if any."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_info(self) -> Dict[str, any]:
|
||||
"""Return the device information."""
|
||||
|
||||
device_information = {
|
||||
"identifiers": {(DOMAIN, self._dev_id)},
|
||||
"name": self._name,
|
||||
"manufacturer": "Plugwise",
|
||||
"model": self._model.replace("_", " ").title(),
|
||||
}
|
||||
|
||||
if self._dev_id != self._api.gateway_id:
|
||||
device_information["via_device"] = (DOMAIN, self._api.gateway_id)
|
||||
del device_information["via_device"]
|
||||
|
||||
return device_information
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend."""
|
||||
return THERMOSTAT_ICON
|
||||
|
||||
@property
|
||||
def supported_features(self):
|
||||
"""Return the list of supported features."""
|
||||
|
@ -172,8 +136,8 @@ class PwThermostat(SmileGateway, ClimateEntity):
|
|||
@property
|
||||
def hvac_modes(self):
|
||||
"""Return the available hvac modes list."""
|
||||
if self._heating_state is not None or self._boiler_state is not None:
|
||||
if self._cooling_state is not None:
|
||||
if self._heating_state is not None:
|
||||
if self._compressor_state is not None:
|
||||
return HVAC_MODES_HEAT_COOL
|
||||
return HVAC_MODES_HEAT_ONLY
|
||||
|
||||
|
@ -258,7 +222,8 @@ class PwThermostat(SmileGateway, ClimateEntity):
|
|||
except Smile.PlugwiseError:
|
||||
_LOGGER.error("Error while communicating to device")
|
||||
|
||||
def _process_data(self):
|
||||
@callback
|
||||
def _async_process_data(self):
|
||||
"""Update the data for this climate device."""
|
||||
climate_data = self._api.get_device_data(self._dev_id)
|
||||
heater_central_data = self._api.get_device_data(self._api.heater_id)
|
||||
|
@ -286,21 +251,18 @@ class PwThermostat(SmileGateway, ClimateEntity):
|
|||
if "active_preset" in climate_data:
|
||||
self._preset_mode = climate_data["active_preset"]
|
||||
|
||||
if "boiler_state" in heater_central_data:
|
||||
if heater_central_data["boiler_state"] is not None:
|
||||
self._boiler_state = heater_central_data["boiler_state"]
|
||||
if "heating_state" in heater_central_data:
|
||||
if heater_central_data["heating_state"] is not None:
|
||||
self._heating_state = heater_central_data["heating_state"]
|
||||
if "cooling_state" in heater_central_data:
|
||||
if heater_central_data["cooling_state"] is not None:
|
||||
self._cooling_state = heater_central_data["cooling_state"]
|
||||
if heater_central_data.get("heating_state") is not None:
|
||||
self._heating_state = heater_central_data["heating_state"]
|
||||
if heater_central_data.get("cooling_state") is not None:
|
||||
self._cooling_state = heater_central_data["cooling_state"]
|
||||
if heater_central_data.get("compressor_state") is not None:
|
||||
self._compressor_state = heater_central_data["compressor_state"]
|
||||
|
||||
if self._schema_status:
|
||||
self._hvac_mode = HVAC_MODE_AUTO
|
||||
elif self._heating_state is not None or self._boiler_state is not None:
|
||||
elif self._heating_state is not None:
|
||||
self._hvac_mode = HVAC_MODE_HEAT
|
||||
if self._cooling_state is not None:
|
||||
if self._compressor_state is not None:
|
||||
self._hvac_mode = HVAC_MODE_HEAT_COOL
|
||||
|
||||
self.async_write_ha_state()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue