From 2f31b8576eed587597f9e9a2602ca18e359ce413 Mon Sep 17 00:00:00 2001 From: mhorst314 Date: Sat, 2 May 2020 20:30:31 +0200 Subject: [PATCH] Fix proliphix (#34397) * Retrieve the name of the Proliphix thermostat before adding the entities * The proliphix module provides hvac_state, not hvac_mode * Removed update before add_entities. Moved the setting of the name into the update function instead. * Disentangled hvac_mode and hvac_action * Ran black and isort --- homeassistant/components/proliphix/climate.py | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/proliphix/climate.py b/homeassistant/components/proliphix/climate.py index fc44dfba75b..5dff4725ea0 100644 --- a/homeassistant/components/proliphix/climate.py +++ b/homeassistant/components/proliphix/climate.py @@ -4,6 +4,10 @@ import voluptuous as vol from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity from homeassistant.components.climate.const import ( + CURRENT_HVAC_COOL, + CURRENT_HVAC_HEAT, + CURRENT_HVAC_IDLE, + CURRENT_HVAC_OFF, HVAC_MODE_COOL, HVAC_MODE_HEAT, HVAC_MODE_OFF, @@ -37,6 +41,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None): host = config.get(CONF_HOST) pdp = proliphix.PDP(host, username, password) + pdp.update() add_entities([ProliphixThermostat(pdp)], True) @@ -47,7 +52,7 @@ class ProliphixThermostat(ClimateEntity): def __init__(self, pdp): """Initialize the thermostat.""" self._pdp = pdp - self._name = self._pdp.name + self._name = None @property def supported_features(self): @@ -62,6 +67,7 @@ class ProliphixThermostat(ClimateEntity): def update(self): """Update the data from the thermostat.""" self._pdp.update() + self._name = self._pdp.name @property def name(self): @@ -97,16 +103,26 @@ class ProliphixThermostat(ClimateEntity): """Return the temperature we try to reach.""" return self._pdp.setback + @property + def hvac_action(self): + """Return the current state of the thermostat.""" + state = self._pdp.hvac_state + if state == 1: + return CURRENT_HVAC_OFF + if state in (3, 4, 5): + return CURRENT_HVAC_HEAT + if state in (6, 7): + return CURRENT_HVAC_COOL + return CURRENT_HVAC_IDLE + @property def hvac_mode(self): """Return the current state of the thermostat.""" - state = self._pdp.hvac_mode - if state in (1, 2): - return HVAC_MODE_OFF - if state == 3: + if self._pdp.is_heating: return HVAC_MODE_HEAT - if state == 6: + if self._pdp.is_cooling: return HVAC_MODE_COOL + return HVAC_MODE_OFF @property def hvac_modes(self):