Skip to content

Commit

Permalink
Add Netatmo temperature services (#104124)
Browse files Browse the repository at this point in the history
* Update datetime strings to match input_datetime integration

* Add netatmo service to set temperature

* Add netatmo service to clear temperature setting

* Fix formatting

* Add tests for new services

* Fix mypy error

* Fix formatting

* Fix formatting

* Apply suggestions from code review (WIP)

Co-authored-by: G Johansson <goran.johansson@shiftit.se>

* Complete changes from review suggestions

* Fix build error

* Add service to set temperature for time period

* Expand and fix test

* Replace duplicated strings with links

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
  • Loading branch information
deosrc and gjohansson-ST committed Nov 23, 2023
1 parent eaba2c7 commit 5623834
Show file tree
Hide file tree
Showing 5 changed files with 363 additions and 4 deletions.
71 changes: 70 additions & 1 deletion homeassistant/components/netatmo/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
ATTR_HEATING_POWER_REQUEST,
ATTR_SCHEDULE_NAME,
ATTR_SELECTED_SCHEDULE,
ATTR_TARGET_TEMPERATURE,
ATTR_TIME_PERIOD,
CONF_URL_ENERGY,
DATA_SCHEDULES,
DOMAIN,
Expand All @@ -47,8 +49,11 @@
EVENT_TYPE_SET_POINT,
EVENT_TYPE_THERM_MODE,
NETATMO_CREATE_CLIMATE,
SERVICE_CLEAR_TEMPERATURE_SETTING,
SERVICE_SET_PRESET_MODE_WITH_END_DATETIME,
SERVICE_SET_SCHEDULE,
SERVICE_SET_TEMPERATURE_WITH_END_DATETIME,
SERVICE_SET_TEMPERATURE_WITH_TIME_PERIOD,
)
from .data_handler import HOME, SIGNAL_NAME, NetatmoRoom
from .netatmo_entity_base import NetatmoBase
Expand Down Expand Up @@ -143,6 +148,34 @@ def _create_entity(netatmo_device: NetatmoRoom) -> None:
},
"_async_service_set_preset_mode_with_end_datetime",
)
platform.async_register_entity_service(
SERVICE_SET_TEMPERATURE_WITH_END_DATETIME,
{
vol.Required(ATTR_TARGET_TEMPERATURE): vol.All(
vol.Coerce(float), vol.Range(min=7, max=30)
),
vol.Required(ATTR_END_DATETIME): cv.datetime,
},
"_async_service_set_temperature_with_end_datetime",
)
platform.async_register_entity_service(
SERVICE_SET_TEMPERATURE_WITH_TIME_PERIOD,
{
vol.Required(ATTR_TARGET_TEMPERATURE): vol.All(
vol.Coerce(float), vol.Range(min=7, max=30)
),
vol.Required(ATTR_TIME_PERIOD): vol.All(
cv.time_period,
cv.positive_timedelta,
),
},
"_async_service_set_temperature_with_time_period",
)
platform.async_register_entity_service(
SERVICE_CLEAR_TEMPERATURE_SETTING,
{},
"_async_service_clear_temperature_setting",
)


class NetatmoThermostat(NetatmoBase, ClimateEntity):
Expand Down Expand Up @@ -441,12 +474,48 @@ async def _async_service_set_preset_mode_with_end_datetime(
mode=PRESET_MAP_NETATMO[preset_mode], end_time=end_timestamp
)
_LOGGER.debug(
"Setting %s preset to %s with optional end datetime to %s",
"Setting %s preset to %s with end datetime %s",
self._room.home.entity_id,
preset_mode,
end_timestamp,
)

async def _async_service_set_temperature_with_end_datetime(
self, **kwargs: Any
) -> None:
target_temperature = kwargs[ATTR_TARGET_TEMPERATURE]
end_datetime = kwargs[ATTR_END_DATETIME]
end_timestamp = int(dt_util.as_timestamp(end_datetime))

_LOGGER.debug(
"Setting %s to target temperature %s with end datetime %s",
self._room.entity_id,
target_temperature,
end_timestamp,
)
await self._room.async_therm_manual(target_temperature, end_timestamp)

async def _async_service_set_temperature_with_time_period(
self, **kwargs: Any
) -> None:
target_temperature = kwargs[ATTR_TARGET_TEMPERATURE]
time_period = kwargs[ATTR_TIME_PERIOD]

_LOGGER.debug(
"Setting %s to target temperature %s with time period %s",
self._room.entity_id,
target_temperature,
time_period,
)

now_timestamp = dt_util.as_timestamp(dt_util.utcnow())
end_timestamp = int(now_timestamp + time_period.seconds)
await self._room.async_therm_manual(target_temperature, end_timestamp)

async def _async_service_clear_temperature_setting(self, **kwargs: Any) -> None:
_LOGGER.debug("Clearing %s temperature setting", self._room.entity_id)
await self._room.async_therm_home()

@property
def device_info(self) -> DeviceInfo:
"""Return the device info for the thermostat."""
Expand Down
5 changes: 5 additions & 0 deletions homeassistant/components/netatmo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,17 @@
ATTR_SCHEDULE_ID = "schedule_id"
ATTR_SCHEDULE_NAME = "schedule_name"
ATTR_SELECTED_SCHEDULE = "selected_schedule"
ATTR_TARGET_TEMPERATURE = "target_temperature"
ATTR_TIME_PERIOD = "time_period"

SERVICE_CLEAR_TEMPERATURE_SETTING = "clear_temperature_setting"
SERVICE_SET_CAMERA_LIGHT = "set_camera_light"
SERVICE_SET_PERSON_AWAY = "set_person_away"
SERVICE_SET_PERSONS_HOME = "set_persons_home"
SERVICE_SET_SCHEDULE = "set_schedule"
SERVICE_SET_PRESET_MODE_WITH_END_DATETIME = "set_preset_mode_with_end_datetime"
SERVICE_SET_TEMPERATURE_WITH_END_DATETIME = "set_temperature_with_end_datetime"
SERVICE_SET_TEMPERATURE_WITH_TIME_PERIOD = "set_temperature_with_time_period"

# Climate events
EVENT_TYPE_CANCEL_SET_POINT = "cancel_set_point"
Expand Down
50 changes: 50 additions & 0 deletions homeassistant/components/netatmo/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,56 @@ set_preset_mode_with_end_datetime:
selector:
datetime:

set_temperature_with_end_datetime:
target:
entity:
integration: netatmo
domain: climate
fields:
target_temperature:
required: true
example: "19.5"
selector:
number:
min: 7
max: 30
step: 0.5
end_datetime:
required: true
example: '"2019-04-20 05:04:20"'
selector:
datetime:

set_temperature_with_time_period:
target:
entity:
integration: netatmo
domain: climate
fields:
target_temperature:
required: true
example: "19.5"
selector:
number:
min: 7
max: 30
step: 0.5
time_period:
required: true
default:
hours: 3
minutes: 0
seconds: 0
days: 0
selector:
duration:

clear_temperature_setting:
target:
entity:
integration: netatmo
domain: climate

set_persons_home:
target:
entity:
Expand Down
38 changes: 35 additions & 3 deletions homeassistant/components/netatmo/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,50 @@
"description": "Unregisters the webhook from the Netatmo backend."
},
"set_preset_mode_with_end_datetime": {
"name": "Set preset mode with end datetime",
"name": "Set preset mode with end date & time",
"description": "Sets the preset mode for a Netatmo climate device. The preset mode must match a preset mode configured at Netatmo.",
"fields": {
"preset_mode": {
"name": "Preset mode",
"description": "Climate preset mode such as Schedule, Away or Frost Guard."
},
"end_datetime": {
"name": "End datetime",
"description": "Datetime for until when the preset will be active."
"name": "End date & time",
"description": "Date & time the preset will be active until."
}
}
},
"set_temperature_with_end_datetime": {
"name": "Set temperature with end date & time",
"description": "Sets the target temperature for a Netatmo climate device with an end date & time.",
"fields": {
"target_temperature": {
"name": "Target temperature",
"description": "The target temperature for the device."
},
"end_datetime": {
"name": "[%key:component::netatmo::services::set_preset_mode_with_end_datetime::fields::end_datetime::name%]",
"description": "Date & time the target temperature will be active until."
}
}
},
"set_temperature_with_time_period": {
"name": "Set temperature with time period",
"description": "Sets the target temperature for a Netatmo climate device with time period.",
"fields": {
"target_temperature": {
"name": "[%key:component::netatmo::services::set_temperature_with_end_datetime::fields::target_temperature::name%]",
"description": "[%key:component::netatmo::services::set_temperature_with_end_datetime::fields::target_temperature::description%]"
},
"time_period": {
"name": "Time period",
"description": "The time period which the temperature setting will be active for."
}
}
},
"clear_temperature_setting": {
"name": "Clear temperature setting",
"description": "Clears any temperature setting for a Netatmo climate device reverting it to the current preset or schedule."
}
}
}

0 comments on commit 5623834

Please sign in to comment.