mirror of
https://github.com/home-assistant/core.git
synced 2025-11-11 03:50:55 +00:00
Compare commits
4 Commits
copilot/ad
...
thermostat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e2a1e6c9d7 | ||
|
|
85de4955b5 | ||
|
|
79f1710ad7 | ||
|
|
8667f1750a |
@@ -148,3 +148,4 @@ class ClimateEntityFeature(IntFlag):
|
||||
TURN_OFF = 128
|
||||
TURN_ON = 256
|
||||
SWING_HORIZONTAL_MODE = 512
|
||||
OCCUPANCY = 1024
|
||||
|
||||
@@ -23,12 +23,26 @@ from homeassistant.components.climate import (
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE, Platform, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.core import (
|
||||
HomeAssistant,
|
||||
ServiceResponse,
|
||||
SupportsResponse,
|
||||
callback,
|
||||
)
|
||||
from homeassistant.helpers import config_validation as cv, entity_platform
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .const import (
|
||||
ATTR_OCCUPANCY,
|
||||
ATTR_UNOCCUPIED_COOLING_TARGET_TEMP,
|
||||
ATTR_UNOCCUPIED_HEATING_TARGET_TEMP,
|
||||
SERVICE_SET_UNOCCUPIED_COOLING_TEMPERATURE,
|
||||
SERVICE_SET_UNOCCUPIED_HEATING_TEMPERATURE,
|
||||
)
|
||||
from .entity import MatterEntity
|
||||
from .helpers import get_matter
|
||||
from .models import MatterDiscoverySchema
|
||||
import voluptuous as vol
|
||||
|
||||
TEMPERATURE_SCALING_FACTOR = 100
|
||||
HVAC_SYSTEM_MODE_MAP = {
|
||||
@@ -170,6 +184,26 @@ class ThermostatRunningState(IntEnum):
|
||||
FanStage2 = 32 # 1 << 5 = 32
|
||||
FanStage3 = 64 # 1 << 6 = 64
|
||||
|
||||
"""
|
||||
platform = entity_platform.async_get_current_platform()
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_UNOCCUPIED_COOLING_TEMPERATURE,
|
||||
schema={
|
||||
vol.Required("unoccupied_cooling_target_temp"): vol.All(cv.positive_int),
|
||||
},
|
||||
func="async_handle_set_unoccupied_cooling_target_temperature",
|
||||
supports_response=SupportsResponse.ONLY,
|
||||
)
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_UNOCCUPIED_HEATING_TEMPERATURE,
|
||||
schema={
|
||||
vol.Required("unoccupied_heating_target_temp"): vol.All(cv.positive_int),
|
||||
},
|
||||
func="async_handle_set_unoccupied_heating_target_temperature",
|
||||
supports_response=SupportsResponse,
|
||||
)
|
||||
"""
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
@@ -192,10 +226,23 @@ class MatterClimate(MatterEntity, ClimateEntity):
|
||||
|
||||
async def async_set_temperature(self, **kwargs: Any) -> None:
|
||||
"""Set new target temperature."""
|
||||
occupancy = kwargs.get(ATTR_OCCUPANCY)
|
||||
target_hvac_mode: HVACMode | None = kwargs.get(ATTR_HVAC_MODE)
|
||||
target_temperature: float | None = kwargs.get(ATTR_TEMPERATURE)
|
||||
target_temperature_low: float | None = kwargs.get(ATTR_TARGET_TEMP_LOW)
|
||||
target_temperature_high: float | None = kwargs.get(ATTR_TARGET_TEMP_HIGH)
|
||||
target_unoccupied_cooling_temp: float | None = kwargs.get(
|
||||
ATTR_UNOCCUPIED_COOLING_TARGET_TEMP
|
||||
)
|
||||
target_unoccupied_heating_temp: float | None = kwargs.get(
|
||||
ATTR_UNOCCUPIED_HEATING_TARGET_TEMP
|
||||
)
|
||||
|
||||
if occupancy is not None:
|
||||
await self.write_attribute(
|
||||
value=1 if occupancy else 0,
|
||||
matter_attribute=clusters.Thermostat.Attributes.Occupancy,
|
||||
)
|
||||
|
||||
if target_hvac_mode is not None:
|
||||
await self.async_set_hvac_mode(target_hvac_mode)
|
||||
@@ -234,6 +281,29 @@ class MatterClimate(MatterEntity, ClimateEntity):
|
||||
matter_attribute=clusters.Thermostat.Attributes.OccupiedCoolingSetpoint,
|
||||
)
|
||||
|
||||
if target_unoccupied_cooling_temp is not None:
|
||||
if (
|
||||
self.extra_state_attributes.get(ATTR_UNOCCUPIED_COOLING_TARGET_TEMP)
|
||||
!= target_unoccupied_cooling_temp
|
||||
):
|
||||
await self.write_attribute(
|
||||
value=int(
|
||||
target_unoccupied_cooling_temp * TEMPERATURE_SCALING_FACTOR
|
||||
),
|
||||
matter_attribute=clusters.Thermostat.Attributes.UnoccupiedCoolingSetpoint,
|
||||
)
|
||||
if target_unoccupied_heating_temp is not None:
|
||||
if (
|
||||
self.extra_state_attributes.get(ATTR_UNOCCUPIED_HEATING_TARGET_TEMP)
|
||||
!= target_unoccupied_heating_temp
|
||||
):
|
||||
await self.write_attribute(
|
||||
value=int(
|
||||
target_unoccupied_heating_temp * TEMPERATURE_SCALING_FACTOR
|
||||
),
|
||||
matter_attribute=clusters.Thermostat.Attributes.UnoccupiedHeatingSetpoint,
|
||||
)
|
||||
|
||||
async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
|
||||
"""Set new target hvac mode."""
|
||||
|
||||
@@ -377,6 +447,8 @@ class MatterClimate(MatterEntity, ClimateEntity):
|
||||
self._attr_supported_features = (
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.TURN_OFF
|
||||
)
|
||||
if feature_map & ThermostatFeature.kOccupancy:
|
||||
self._attr_supported_features |= ClimateEntityFeature.OCCUPANCY
|
||||
if feature_map & ThermostatFeature.kHeating:
|
||||
self._attr_hvac_modes.append(HVACMode.HEAT)
|
||||
if feature_map & ThermostatFeature.kCooling:
|
||||
@@ -426,6 +498,7 @@ DISCOVERY_SCHEMAS = [
|
||||
clusters.Thermostat.Attributes.ThermostatRunningMode,
|
||||
clusters.Thermostat.Attributes.ThermostatRunningState,
|
||||
clusters.Thermostat.Attributes.TemperatureSetpointHold,
|
||||
clusters.Thermostat.Attributes.Occupancy,
|
||||
clusters.Thermostat.Attributes.UnoccupiedCoolingSetpoint,
|
||||
clusters.Thermostat.Attributes.UnoccupiedHeatingSetpoint,
|
||||
clusters.OnOff.Attributes.OnOff,
|
||||
|
||||
@@ -15,3 +15,10 @@ ID_TYPE_DEVICE_ID = "deviceid"
|
||||
ID_TYPE_SERIAL = "serial"
|
||||
|
||||
FEATUREMAP_ATTRIBUTE_ID = 65532
|
||||
|
||||
SERVICE_SET_UNOCCUPIED_COOLING_TEMPERATURE = "set_unoccupied_cooling_target_temperature"
|
||||
SERVICE_SET_UNOCCUPIED_HEATING_TEMPERATURE = "set_unoccupied_heating_target_temperature"
|
||||
|
||||
ATTR_OCCUPANCY = "occupancy"
|
||||
ATTR_UNOCCUPIED_COOLING_TARGET_TEMP = "unoccupied_cooling_target_temp"
|
||||
ATTR_UNOCCUPIED_HEATING_TARGET_TEMP = "unoccupied_heating_target_temp"
|
||||
|
||||
36
homeassistant/components/matter/services.yaml
Normal file
36
homeassistant/components/matter/services.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
unoccupied_cooling_target_temp:
|
||||
target:
|
||||
entity:
|
||||
domain: climate
|
||||
supported_features:
|
||||
- climate.ClimateEntityFeature.OCCUPANCY
|
||||
fields:
|
||||
target_unoccupied_cool_temp:
|
||||
filter:
|
||||
supported_features:
|
||||
- climate.ClimateEntityFeature.OCCUPANCY
|
||||
selector:
|
||||
number:
|
||||
min: 0
|
||||
max: 250
|
||||
step: 0.1
|
||||
mode: box
|
||||
|
||||
unoccupied_heating_target_temp:
|
||||
target:
|
||||
entity:
|
||||
domain: climate
|
||||
supported_features:
|
||||
- climate.ClimateEntityFeature.OCCUPANCY
|
||||
fields:
|
||||
target_unoccupied_heat_temp:
|
||||
filter:
|
||||
supported_features:
|
||||
- climate.ClimateEntityFeature.OCCUPANCY
|
||||
advanced: true
|
||||
selector:
|
||||
number:
|
||||
min: 0
|
||||
max: 250
|
||||
step: 0.1
|
||||
mode: box
|
||||
Reference in New Issue
Block a user