mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
expose schedule id as an extra state attribute in Netatmo (#147076)
This commit is contained in:
parent
ab187f39c2
commit
8256401f7f
@ -38,6 +38,7 @@ from .const import (
|
|||||||
ATTR_HEATING_POWER_REQUEST,
|
ATTR_HEATING_POWER_REQUEST,
|
||||||
ATTR_SCHEDULE_NAME,
|
ATTR_SCHEDULE_NAME,
|
||||||
ATTR_SELECTED_SCHEDULE,
|
ATTR_SELECTED_SCHEDULE,
|
||||||
|
ATTR_SELECTED_SCHEDULE_ID,
|
||||||
ATTR_TARGET_TEMPERATURE,
|
ATTR_TARGET_TEMPERATURE,
|
||||||
ATTR_TIME_PERIOD,
|
ATTR_TIME_PERIOD,
|
||||||
DATA_SCHEDULES,
|
DATA_SCHEDULES,
|
||||||
@ -251,16 +252,22 @@ class NetatmoThermostat(NetatmoRoomEntity, ClimateEntity):
|
|||||||
if data["event_type"] == EVENT_TYPE_SCHEDULE:
|
if data["event_type"] == EVENT_TYPE_SCHEDULE:
|
||||||
# handle schedule change
|
# handle schedule change
|
||||||
if "schedule_id" in data:
|
if "schedule_id" in data:
|
||||||
|
selected_schedule = self.hass.data[DOMAIN][DATA_SCHEDULES][
|
||||||
|
self.home.entity_id
|
||||||
|
].get(data["schedule_id"])
|
||||||
self._selected_schedule = getattr(
|
self._selected_schedule = getattr(
|
||||||
self.hass.data[DOMAIN][DATA_SCHEDULES][self.home.entity_id].get(
|
selected_schedule,
|
||||||
data["schedule_id"]
|
|
||||||
),
|
|
||||||
"name",
|
"name",
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
self._attr_extra_state_attributes[ATTR_SELECTED_SCHEDULE] = (
|
self._attr_extra_state_attributes[ATTR_SELECTED_SCHEDULE] = (
|
||||||
self._selected_schedule
|
self._selected_schedule
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._attr_extra_state_attributes[ATTR_SELECTED_SCHEDULE_ID] = getattr(
|
||||||
|
selected_schedule, "entity_id", None
|
||||||
|
)
|
||||||
|
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
self.data_handler.async_force_update(self._signal_name)
|
self.data_handler.async_force_update(self._signal_name)
|
||||||
# ignore other schedule events
|
# ignore other schedule events
|
||||||
@ -420,12 +427,14 @@ class NetatmoThermostat(NetatmoRoomEntity, ClimateEntity):
|
|||||||
self._attr_hvac_mode = HVAC_MAP_NETATMO[self._attr_preset_mode]
|
self._attr_hvac_mode = HVAC_MAP_NETATMO[self._attr_preset_mode]
|
||||||
self._away = self._attr_hvac_mode == HVAC_MAP_NETATMO[STATE_NETATMO_AWAY]
|
self._away = self._attr_hvac_mode == HVAC_MAP_NETATMO[STATE_NETATMO_AWAY]
|
||||||
|
|
||||||
self._selected_schedule = getattr(
|
selected_schedule = self.home.get_selected_schedule()
|
||||||
self.home.get_selected_schedule(), "name", None
|
self._selected_schedule = getattr(selected_schedule, "name", None)
|
||||||
)
|
|
||||||
self._attr_extra_state_attributes[ATTR_SELECTED_SCHEDULE] = (
|
self._attr_extra_state_attributes[ATTR_SELECTED_SCHEDULE] = (
|
||||||
self._selected_schedule
|
self._selected_schedule
|
||||||
)
|
)
|
||||||
|
self._attr_extra_state_attributes[ATTR_SELECTED_SCHEDULE_ID] = getattr(
|
||||||
|
selected_schedule, "entity_id", None
|
||||||
|
)
|
||||||
|
|
||||||
if self.device_type == NA_VALVE:
|
if self.device_type == NA_VALVE:
|
||||||
self._attr_extra_state_attributes[ATTR_HEATING_POWER_REQUEST] = (
|
self._attr_extra_state_attributes[ATTR_HEATING_POWER_REQUEST] = (
|
||||||
|
@ -95,6 +95,7 @@ ATTR_PSEUDO = "pseudo"
|
|||||||
ATTR_SCHEDULE_ID = "schedule_id"
|
ATTR_SCHEDULE_ID = "schedule_id"
|
||||||
ATTR_SCHEDULE_NAME = "schedule_name"
|
ATTR_SCHEDULE_NAME = "schedule_name"
|
||||||
ATTR_SELECTED_SCHEDULE = "selected_schedule"
|
ATTR_SELECTED_SCHEDULE = "selected_schedule"
|
||||||
|
ATTR_SELECTED_SCHEDULE_ID = "selected_schedule_id"
|
||||||
ATTR_TARGET_TEMPERATURE = "target_temperature"
|
ATTR_TARGET_TEMPERATURE = "target_temperature"
|
||||||
ATTR_TIME_PERIOD = "time_period"
|
ATTR_TIME_PERIOD = "time_period"
|
||||||
|
|
||||||
|
@ -147,6 +147,7 @@
|
|||||||
'schedule',
|
'schedule',
|
||||||
]),
|
]),
|
||||||
'selected_schedule': 'Default',
|
'selected_schedule': 'Default',
|
||||||
|
'selected_schedule_id': '591b54a2764ff4d50d8b5795',
|
||||||
'supported_features': <ClimateEntityFeature: 401>,
|
'supported_features': <ClimateEntityFeature: 401>,
|
||||||
'target_temp_step': 0.5,
|
'target_temp_step': 0.5,
|
||||||
'temperature': 7,
|
'temperature': 7,
|
||||||
@ -229,6 +230,7 @@
|
|||||||
'schedule',
|
'schedule',
|
||||||
]),
|
]),
|
||||||
'selected_schedule': 'Default',
|
'selected_schedule': 'Default',
|
||||||
|
'selected_schedule_id': '591b54a2764ff4d50d8b5795',
|
||||||
'supported_features': <ClimateEntityFeature: 401>,
|
'supported_features': <ClimateEntityFeature: 401>,
|
||||||
'target_temp_step': 0.5,
|
'target_temp_step': 0.5,
|
||||||
'temperature': 22,
|
'temperature': 22,
|
||||||
@ -312,6 +314,7 @@
|
|||||||
'schedule',
|
'schedule',
|
||||||
]),
|
]),
|
||||||
'selected_schedule': 'Default',
|
'selected_schedule': 'Default',
|
||||||
|
'selected_schedule_id': '591b54a2764ff4d50d8b5795',
|
||||||
'supported_features': <ClimateEntityFeature: 401>,
|
'supported_features': <ClimateEntityFeature: 401>,
|
||||||
'target_temp_step': 0.5,
|
'target_temp_step': 0.5,
|
||||||
'temperature': 7,
|
'temperature': 7,
|
||||||
@ -396,6 +399,7 @@
|
|||||||
'schedule',
|
'schedule',
|
||||||
]),
|
]),
|
||||||
'selected_schedule': 'Default',
|
'selected_schedule': 'Default',
|
||||||
|
'selected_schedule_id': '591b54a2764ff4d50d8b5795',
|
||||||
'supported_features': <ClimateEntityFeature: 401>,
|
'supported_features': <ClimateEntityFeature: 401>,
|
||||||
'target_temp_step': 0.5,
|
'target_temp_step': 0.5,
|
||||||
'temperature': 12,
|
'temperature': 12,
|
||||||
|
@ -681,6 +681,13 @@ async def test_service_schedule_thermostats(
|
|||||||
webhook_id = config_entry.data[CONF_WEBHOOK_ID]
|
webhook_id = config_entry.data[CONF_WEBHOOK_ID]
|
||||||
climate_entity_livingroom = "climate.livingroom"
|
climate_entity_livingroom = "climate.livingroom"
|
||||||
|
|
||||||
|
assert (
|
||||||
|
hass.states.get(climate_entity_livingroom).attributes.get(
|
||||||
|
"selected_schedule_id"
|
||||||
|
)
|
||||||
|
== "591b54a2764ff4d50d8b5795"
|
||||||
|
)
|
||||||
|
|
||||||
# Test setting a valid schedule
|
# Test setting a valid schedule
|
||||||
with patch("pyatmo.home.Home.async_switch_schedule") as mock_switch_schedule:
|
with patch("pyatmo.home.Home.async_switch_schedule") as mock_switch_schedule:
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
@ -707,6 +714,12 @@ async def test_service_schedule_thermostats(
|
|||||||
hass.states.get(climate_entity_livingroom).attributes["selected_schedule"]
|
hass.states.get(climate_entity_livingroom).attributes["selected_schedule"]
|
||||||
== "Winter"
|
== "Winter"
|
||||||
)
|
)
|
||||||
|
assert (
|
||||||
|
hass.states.get(climate_entity_livingroom).attributes.get(
|
||||||
|
"selected_schedule_id"
|
||||||
|
)
|
||||||
|
== "b1b54a2f45795764f59d50d8"
|
||||||
|
)
|
||||||
|
|
||||||
# Test setting an invalid schedule
|
# Test setting an invalid schedule
|
||||||
with patch("pyatmo.home.Home.async_switch_schedule") as mock_switch_home_schedule:
|
with patch("pyatmo.home.Home.async_switch_schedule") as mock_switch_home_schedule:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user