Update Plugwise (#28237)

* Plugwise update

* Fix DEFAULT_NAME

* Fix pylint errors

* Remove showing of DHW-status

* Remove `if not None` where possible

* Forgot to remove dhw-related code

* Updated w.r.t. comments from MartinHjelmare

* Remove the illuminance attribute - move to sensor

* Update homeassistant/components/plugwise/climate.py

Co-Authored-By: Martin Hjelmare <marhje52@kth.se>

* Breaking lines

* Remove thermostat_temperature

* Try fix lint errors.

* Remove spaces

* Remove more spaces
This commit is contained in:
Bouwe Westerdijk 2019-11-05 02:58:17 +01:00 committed by Martin Hjelmare
parent ade60742d4
commit fb0e20543e
4 changed files with 118 additions and 45 deletions

View file

@ -229,7 +229,7 @@ homeassistant/components/pi_hole/* @fabaff @johnluetke
homeassistant/components/plaato/* @JohNan
homeassistant/components/plant/* @ChristianKuehnel
homeassistant/components/plex/* @jjlawren
homeassistant/components/plugwise/* @laetificat @CoMPaTech
homeassistant/components/plugwise/* @laetificat @CoMPaTech @bouwew
homeassistant/components/point/* @fredrike
homeassistant/components/ps4/* @ktnrg45
homeassistant/components/ptvsd/* @swamp-ig

View file

@ -9,9 +9,11 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateDevice
from homeassistant.components.climate.const import (
CURRENT_HVAC_HEAT,
CURRENT_HVAC_COOL,
CURRENT_HVAC_IDLE,
HVAC_MODE_HEAT,
HVAC_MODE_HEAT_COOL,
HVAC_MODE_AUTO,
HVAC_MODE_OFF,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
)
@ -33,6 +35,7 @@ _LOGGER = logging.getLogger(__name__)
# Configuration directives
CONF_MIN_TEMP = "min_temp"
CONF_MAX_TEMP = "max_temp"
CONF_LEGACY = "legacy_anna"
# Default directives
DEFAULT_NAME = "Plugwise Thermostat"
@ -44,7 +47,8 @@ DEFAULT_MIN_TEMP = 4
DEFAULT_MAX_TEMP = 30
# HVAC modes
ATTR_HVAC_MODES = [HVAC_MODE_AUTO, HVAC_MODE_OFF]
HVAC_MODES_1 = [HVAC_MODE_HEAT, HVAC_MODE_AUTO]
HVAC_MODES_2 = [HVAC_MODE_HEAT_COOL, HVAC_MODE_AUTO]
# Read platform configuration
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
@ -52,6 +56,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_HOST): cv.string,
vol.Optional(CONF_LEGACY, default=False): cv.boolean,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
vol.Optional(CONF_MIN_TEMP, default=DEFAULT_MIN_TEMP): cv.positive_int,
@ -67,6 +72,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
config[CONF_PASSWORD],
config[CONF_HOST],
config[CONF_PORT],
config[CONF_LEGACY],
)
try:
api.ping_anna_thermostat()
@ -92,15 +98,28 @@ class ThermostatDevice(ClimateDevice):
self._name = name
self._domain_objects = None
self._outdoor_temperature = None
self._active_schema = None
self._selected_schema = None
self._preset_mode = None
self._hvac_modes = ATTR_HVAC_MODES
self._presets = None
self._presets_list = None
self._heating_status = None
self._cooling_status = None
self._schema_names = None
self._schema_status = None
self._current_temperature = None
self._thermostat_temperature = None
self._boiler_temperature = None
self._water_pressure = None
self._schedule_temperature = None
self._hvac_mode = None
@property
def hvac_action(self):
"""Return the current action."""
if self._api.get_heating_status(self._domain_objects):
if self._heating_status:
return CURRENT_HVAC_HEAT
if self._cooling_status:
return CURRENT_HVAC_COOL
return CURRENT_HVAC_IDLE
@property
@ -122,49 +141,80 @@ class ThermostatDevice(ClimateDevice):
def device_state_attributes(self):
"""Return the device specific state attributes."""
attributes = {}
attributes["outdoor_temperature"] = self._outdoor_temperature
attributes["available_schemas"] = self._api.get_schema_names(
self._domain_objects
)
attributes["active_schema"] = self._active_schema
if self._outdoor_temperature:
attributes["outdoor_temperature"] = self._outdoor_temperature
attributes["available_schemas"] = self._schema_names
attributes["selected_schema"] = self._selected_schema
if self._boiler_temperature:
attributes["boiler_temperature"] = self._boiler_temperature
if self._water_pressure:
attributes["water_pressure"] = self._water_pressure
return attributes
def update(self):
"""Update the data from the thermostat."""
_LOGGER.debug("Update called")
self._domain_objects = self._api.get_domain_objects()
self._outdoor_temperature = self._api.get_outdoor_temperature(
self._domain_objects
)
self._active_schema = self._api.get_active_schema_name(self._domain_objects)
@property
def preset_modes(self):
"""Return the available preset modes list.
And make the presets with their temperatures available.
"""
return self._presets_list
@property
def hvac_modes(self):
"""Return the available hvac modes list."""
if self._heating_status is not None:
if self._cooling_status is not None:
return HVAC_MODES_2
return HVAC_MODES_1
return None
@property
def hvac_mode(self):
"""Return current active hvac state."""
if self._api.get_schema_state(self._domain_objects):
if self._schema_status:
return HVAC_MODE_AUTO
return HVAC_MODE_OFF
if self._heating_status:
if self._cooling_status:
return HVAC_MODE_HEAT_COOL
return HVAC_MODE_HEAT
return None
@property
def target_temperature(self):
"""Return the target_temperature.
From the XML the thermostat-value is used because it updates 'immediately'
compared to the target_temperature-value. This way the information on the card
is "immediately" updated after changing the preset, temperature, etc.
"""
return self._thermostat_temperature
@property
def preset_mode(self):
"""Return the active preset mode."""
return self._api.get_current_preset(self._domain_objects)
"""Return the active selected schedule-name.
@property
def preset_modes(self):
"""Return the available preset modes list without values."""
presets = list(self._api.get_presets(self._domain_objects))
return presets
@property
def hvac_modes(self):
"""Return the available hvac modes list."""
return self._hvac_modes
Or return the active preset, or return Temporary in case of a manual change
in the set-temperature with a weekschedule active,
or return Manual in case of a manual change and no weekschedule active.
"""
if self._presets:
presets = self._presets
preset_temperature = presets.get(self._preset_mode, "none")
if self.hvac_mode == HVAC_MODE_AUTO:
if self._thermostat_temperature == self._schedule_temperature:
return "{}".format(self._selected_schema)
if self._thermostat_temperature == preset_temperature:
return self._preset_mode
return "Temporary"
if self._thermostat_temperature != preset_temperature:
return "Manual"
return self._preset_mode
return None
@property
def current_temperature(self):
"""Return the current temperature."""
return self._api.get_temperature(self._domain_objects)
"""Return the current room temperature."""
return self._current_temperature
@property
def min_temp(self):
@ -176,11 +226,6 @@ class ThermostatDevice(ClimateDevice):
"""Return the maximum temperature possible to set."""
return self._max_temp
@property
def target_temperature(self):
"""Return the target temperature."""
return self._api.get_target_temperature(self._domain_objects)
@property
def temperature_unit(self):
"""Return the unit of measured temperature."""
@ -203,11 +248,39 @@ class ThermostatDevice(ClimateDevice):
if hvac_mode == HVAC_MODE_AUTO:
schema_mode = "true"
self._api.set_schema_state(
self._domain_objects, self._active_schema, schema_mode
self._domain_objects, self._selected_schema, schema_mode
)
def set_preset_mode(self, preset_mode):
"""Set the preset mode."""
_LOGGER.debug("Changing preset mode")
self._preset_mode = preset_mode
self._api.set_preset(self._domain_objects, preset_mode)
def update(self):
"""Update the data from the thermostat."""
_LOGGER.debug("Update called")
self._domain_objects = self._api.get_domain_objects()
self._outdoor_temperature = self._api.get_outdoor_temperature(
self._domain_objects
)
self._selected_schema = self._api.get_active_schema_name(self._domain_objects)
self._preset_mode = self._api.get_current_preset(self._domain_objects)
self._presets = self._api.get_presets(self._domain_objects)
self._presets_list = list(self._api.get_presets(self._domain_objects))
self._heating_status = self._api.get_heating_status(self._domain_objects)
self._cooling_status = self._api.get_cooling_status(self._domain_objects)
self._schema_names = self._api.get_schema_names(self._domain_objects)
self._schema_status = self._api.get_schema_state(self._domain_objects)
self._current_temperature = self._api.get_current_temperature(
self._domain_objects
)
self._thermostat_temperature = self._api.get_thermostat_temperature(
self._domain_objects
)
self._schedule_temperature = self._api.get_schedule_temperature(
self._domain_objects
)
self._boiler_temperature = self._api.get_boiler_temperature(
self._domain_objects
)
self._water_pressure = self._api.get_water_pressure(self._domain_objects)

View file

@ -3,6 +3,6 @@
"name": "Plugwise",
"documentation": "https://www.home-assistant.io/integrations/plugwise",
"dependencies": [],
"codeowners": ["@laetificat","@CoMPaTech"],
"requirements": ["haanna==0.10.1"]
"codeowners": ["@laetificat","@CoMPaTech","@bouwew"],
"requirements": ["haanna==0.13.5"]
}

View file

@ -613,7 +613,7 @@ ha-ffmpeg==2.0
ha-philipsjs==0.0.8
# homeassistant.components.plugwise
haanna==0.10.1
haanna==0.13.5
# homeassistant.components.habitica
habitipy==0.2.0