Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Netatmo temperature services #104124

Merged
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(
deosrc marked this conversation as resolved.
Show resolved Hide resolved
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": "End date & time",
deosrc marked this conversation as resolved.
Show resolved Hide resolved
"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": "Target temperature",
"description": "The target temperature for the device."
},
"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."
}
}
}