Compare commits

...

4 Commits

Author SHA1 Message Date
Jean-Marc Collin 115df52f67 Issue#36 - Error at initialisation
Issue#32 - Error with Fan Modes on thermostat over climate type
2023-01-31 22:19:43 +01:00
Jean-Marc Collin 3371197594 Fix issue#32 Error with Fan Modes on thermostat over climate type 2023-01-31 09:35:27 +01:00
Jean-Marc Collin 7e63c9aa79 Heater can restart after HVAC_MODE_OFF 2023-01-30 07:09:43 +01:00
Jean-Marc Collin 100cfaeac9 Add binary sensors for window sensors 2023-01-30 06:49:39 +01:00
5 changed files with 115 additions and 9 deletions
@@ -220,6 +220,8 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
self._is_over_climate = False
self._underlying_climate = None
self._attr_translation_key = "versatile_thermostat"
self.post_init(entry_infos)
def post_init(self, entry_infos):
@@ -774,6 +776,50 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
return self._hvac_list
@property
def fan_mode(self) -> str | None:
"""Return the fan setting.
Requires ClimateEntityFeature.FAN_MODE.
"""
if self._is_over_climate and self._underlying_climate:
return self._underlying_climate.fan_mode
return None
@property
def fan_modes(self) -> list[str] | None:
"""Return the list of available fan modes.
Requires ClimateEntityFeature.FAN_MODE.
"""
if self._is_over_climate and self._underlying_climate:
return self._underlying_climate.fan_modes
return []
@property
def swing_mode(self) -> str | None:
"""Return the swing setting.
Requires ClimateEntityFeature.SWING_MODE.
"""
if self._is_over_climate and self._underlying_climate:
return self._underlying_climate.swing_mode
return None
@property
def swing_modes(self) -> list[str] | None:
"""Return the list of available swing modes.
Requires ClimateEntityFeature.SWING_MODE.
"""
if self._is_over_climate and self._underlying_climate:
return self._underlying_climate.swing_modes
return None
@property
def temperature_unit(self):
"""Return the unit of measurement."""
@@ -820,10 +866,16 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
@property
def _is_device_active(self):
"""If the toggleable device is currently active."""
if self._is_over_climate or not self.hass.states.get(self._heater_entity_id):
return None
return self.hass.states.is_state(self._heater_entity_id, STATE_ON)
if self._is_over_climate:
if self._underlying_climate:
return self._underlying_climate.hvac_action not in [
CURRENT_HVAC_IDLE,
CURRENT_HVAC_OFF,
]
else:
return None
else:
return self.hass.states.is_state(self._heater_entity_id, STATE_ON)
@property
def current_temperature(self):
@@ -834,6 +886,9 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
"""Set new target hvac mode."""
_LOGGER.info("%s - Set hvac mode: %s", self, hvac_mode)
if hvac_mode is None:
return
if self._is_over_climate and self._underlying_climate:
data = {ATTR_ENTITY_ID: self._climate_entity_id, "hvac_mode": hvac_mode}
await self.hass.services.async_call(
@@ -1377,11 +1432,17 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
async def _async_underlying_entity_turn_off(self):
"""Turn heater toggleable device off."""
if not self._is_over_climate:
_LOGGER.debug(
"%s - Stopping underlying switch %s", self, self._heater_entity_id
)
data = {ATTR_ENTITY_ID: self._heater_entity_id}
await self.hass.services.async_call(
HA_DOMAIN, SERVICE_TURN_OFF, data, context=self._context
)
else:
_LOGGER.debug(
"%s - Stopping underlying switch %s", self, self._climate_entity_id
)
data = {ATTR_ENTITY_ID: self._climate_entity_id}
await self.hass.services.async_call(
HA_DOMAIN, SERVICE_TURN_OFF, data, context=self._context
@@ -1567,16 +1628,19 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
# Check overpowering condition
overpowering: bool = await self.check_overpowering()
if overpowering:
_LOGGER.debug("%s - End of cycle (0)", self)
_LOGGER.debug("%s - End of cycle (overpowering)", self)
return
security: bool = await self.check_security()
if security:
_LOGGER.debug("%s - End of cycle (1)", self)
_LOGGER.debug("%s - End of cycle (security)", self)
return
# Stop here if we are off
if self._hvac_mode == HVAC_MODE_OFF:
_LOGGER.debug("%s - End of cycle (HVAC_MODE_OFF)", self)
if self._is_device_active:
await self._async_underlying_entity_turn_off()
return
if not self._is_over_climate:
@@ -1616,6 +1680,12 @@ class VersatileThermostat(ClimateEntity, RestoreEntity):
self._async_cancel_cycle = None
_LOGGER.debug("%s - Stopping cycle during calculation", self)
if self._hvac_mode == HVAC_MODE_OFF:
_LOGGER.debug("%s - End of cycle (HVAC_MODE_OFF - 2)", self)
if self._is_device_active:
await self._async_underlying_entity_turn_off()
return
if on:
security = (
await self.check_security()
@@ -211,12 +211,12 @@ class VersatileThermostatBaseConfigFlow(FlowHandler):
elif is_power_sensor(v):
_LOGGER.debug("Power sensor !")
power_sensors.append(k)
elif k.startswith(PERSON_DOMAIN) or k.startswith(BINARY_SENSOR_DOMAIN):
elif k.startswith(PERSON_DOMAIN):
_LOGGER.debug("Presence sensor !")
presence_sensors.append(k)
# window sensor
if k.startswith(INPUT_BOOLEAN_DOMAIN):
# window sensor and presence
if k.startswith(INPUT_BOOLEAN_DOMAIN) or k.startswith(BINARY_SENSOR_DOMAIN):
_LOGGER.debug("Window or presence sensor !")
window_sensors.append(k)
presence_sensors.append(k)
@@ -209,5 +209,17 @@
"thermostat_over_climate": "Thermostat over another thermostat"
}
}
},
"entity": {
"climate": {
"versatile_thermostat": {
"states_attributes": {
"preset_mode": {
"power": "Shedding",
"security": "Security"
}
}
}
}
}
}
@@ -209,5 +209,17 @@
"thermostat_over_climate": "Thermostat over another thermostat"
}
}
},
"entity": {
"climate": {
"versatile_thermostat": {
"states_attributes": {
"preset_mode": {
"power": "Shedding",
"security": "Security"
}
}
}
}
}
}
@@ -209,5 +209,17 @@
"thermostat_over_climate": "Thermostat sur un autre thermostat"
}
}
},
"entity": {
"climate": {
"versatile_thermostat": {
"states_attributes": {
"preset_mode": {
"power": "Délestage",
"security": "Sécurité"
}
}
}
}
}
}