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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting the nexia run mode with the hvac mode #57940

Merged
merged 4 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
30 changes: 30 additions & 0 deletions homeassistant/components/nexia/climate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Support for Nexia / Trane XL thermostats."""
from nexia.const import (
HOLD_PERMANENT,
HOLD_RESUME_SCHEDULE,
OPERATION_MODE_AUTO,
OPERATION_MODE_COOL,
OPERATION_MODE_HEAT,
Expand All @@ -14,6 +16,7 @@
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
ATTR_HUMIDITY,
ATTR_HVAC_MODE,
ATTR_MAX_HUMIDITY,
ATTR_MIN_HUMIDITY,
ATTR_TARGET_TEMP_HIGH,
Expand Down Expand Up @@ -45,6 +48,7 @@
ATTR_DEHUMIDIFY_SUPPORTED,
ATTR_HUMIDIFY_SETPOINT,
ATTR_HUMIDIFY_SUPPORTED,
ATTR_RUN_MODE,
ATTR_ZONE_STATUS,
DOMAIN,
SIGNAL_THERMOSTAT_UPDATE,
Expand All @@ -56,6 +60,7 @@

SERVICE_SET_AIRCLEANER_MODE = "set_aircleaner_mode"
SERVICE_SET_HUMIDIFY_SETPOINT = "set_humidify_setpoint"
SERVICE_SET_HVAC_RUN_MODE = "set_hvac_run_mode"

SET_AIRCLEANER_SCHEMA = {
vol.Required(ATTR_AIRCLEANER_MODE): cv.string,
Expand All @@ -65,6 +70,17 @@
vol.Required(ATTR_HUMIDITY): vol.All(vol.Coerce(int), vol.Range(min=35, max=65)),
}

SET_HVAC_RUN_MODE_SCHEMA = vol.All(
cv.has_at_least_one_key(ATTR_RUN_MODE, ATTR_HVAC_MODE),
cv.make_entity_service_schema(
{
vol.Optional(ATTR_RUN_MODE): vol.In([HOLD_PERMANENT, HOLD_RESUME_SCHEDULE]),
vol.Optional(ATTR_HVAC_MODE): vol.In(
[HVAC_MODE_HEAT, HVAC_MODE_COOL, HVAC_MODE_AUTO]
),
}
),
)

#
# Nexia has two bits to determine hvac mode
Expand Down Expand Up @@ -102,6 +118,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
platform.async_register_entity_service(
SERVICE_SET_AIRCLEANER_MODE, SET_AIRCLEANER_SCHEMA, SERVICE_SET_AIRCLEANER_MODE
)
platform.async_register_entity_service(
SERVICE_SET_HVAC_RUN_MODE, SET_HVAC_RUN_MODE_SCHEMA, SERVICE_SET_HVAC_RUN_MODE
)

entities = []
for thermostat_id in nexia_home.get_thermostat_ids():
Expand Down Expand Up @@ -188,6 +207,17 @@ def set_fan_mode(self, fan_mode):
self._thermostat.set_fan_mode(fan_mode)
self._signal_thermostat_update()

def set_hvac_run_mode(self, run_mode, hvac_mode):
"""Set the hvac run mode."""
if run_mode is not None:
if run_mode == HOLD_PERMANENT:
self._zone.call_permanent_hold()
else:
self._zone.call_return_to_schedule()
if hvac_mode is not None:
self._zone.set_mode(mode=HA_TO_NEXIA_HVAC_MODE_MAP[hvac_mode])
self._signal_thermostat_update()

@property
def preset_mode(self):
"""Preset that is active."""
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/nexia/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

ATTR_AIRCLEANER_MODE = "aircleaner_mode"

ATTR_RUN_MODE = "run_mode"

ATTR_ZONE_STATUS = "zone_status"
ATTR_HUMIDIFY_SUPPORTED = "humidify_supported"
ATTR_DEHUMIDIFY_SUPPORTED = "dehumidify_supported"
Expand Down
28 changes: 28 additions & 0 deletions homeassistant/components/nexia/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,31 @@ set_humidify_setpoint:
min: 35
max: 65
unit_of_measurement: '%'

set_hvac_run_mode:
name: Set hvac run mode
description: "The hvac run mode."
target:
entity:
integration: nexia
domain: climate
fields:
run_mode:
name: Run mode
description: 'Run the schedule or hold. If not specified, the current run mode will be used.'
required: false
selector:
select:
options:
- 'permanent_hold'
- 'run_schedule'
hvac_mode:
name: Hvac mode
description: 'The hvac mode to use for the schedule or hold. If not specified, the current hvac mode will be used.'
required: false
selector:
select:
options:
- 'auto'
- 'cool'
- 'heat'