1 """Support for NuHeat thermostats."""
6 from nuheat.config
import SCHEDULE_HOLD, SCHEDULE_RUN, SCHEDULE_TEMPORARY_HOLD
7 from nuheat.util
import (
29 from .const
import DOMAIN, MANUFACTURER, NUHEAT_API_STATE_SHIFT_DELAY
31 _LOGGER = logging.getLogger(__name__)
36 OPERATION_LIST = [HVACMode.AUTO, HVACMode.HEAT]
38 PRESET_RUN =
"Run Schedule"
39 PRESET_TEMPORARY_HOLD =
"Temporary Hold"
40 PRESET_PERMANENT_HOLD =
"Permanent Hold"
42 PRESET_MODES = [PRESET_RUN, PRESET_TEMPORARY_HOLD, PRESET_PERMANENT_HOLD]
44 PRESET_MODE_TO_SCHEDULE_MODE_MAP = {
45 PRESET_RUN: SCHEDULE_RUN,
46 PRESET_TEMPORARY_HOLD: SCHEDULE_TEMPORARY_HOLD,
47 PRESET_PERMANENT_HOLD: SCHEDULE_HOLD,
50 SCHEDULE_MODE_TO_PRESET_MODE_MAP = {
51 value: key
for key, value
in PRESET_MODE_TO_SCHEDULE_MODE_MAP.items()
57 config_entry: ConfigEntry,
58 async_add_entities: AddEntitiesCallback,
60 """Set up the NuHeat thermostat(s)."""
61 thermostat, coordinator = hass.data[DOMAIN][config_entry.entry_id]
63 temperature_unit = hass.config.units.temperature_unit
73 """Representation of a NuHeat Thermostat."""
75 _attr_hvac_modes = OPERATION_LIST
76 _attr_supported_features = (
77 ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
79 _attr_has_entity_name =
True
81 _attr_preset_modes = PRESET_MODES
82 _enable_turn_on_off_backwards_compatibility =
False
84 def __init__(self, coordinator, thermostat, temperature_unit):
85 """Initialize the thermostat."""
95 """Return the unit of measurement."""
97 return UnitOfTemperature.CELSIUS
99 return UnitOfTemperature.FAHRENHEIT
103 """Return the current temperature."""
111 """Return the unique id."""
112 return self.coordinator.last_update_success
and self.
_thermostat_thermostat.online
115 """Set the system mode."""
116 if hvac_mode == HVACMode.AUTO:
118 elif hvac_mode == HVACMode.HEAT:
123 """Return current setting heat or auto."""
124 if self.
_schedule_mode_schedule_mode
in (SCHEDULE_TEMPORARY_HOLD, SCHEDULE_HOLD):
130 """Return current operation heat or idle."""
131 return HVACAction.HEATING
if self.
_thermostat_thermostat.heating
else HVACAction.IDLE
135 """Return the minimum supported temperature for the thermostat."""
143 """Return the maximum supported temperature for the thermostat."""
151 """Return the currently programmed temperature."""
159 """Return current preset mode."""
160 return SCHEDULE_MODE_TO_PRESET_MODE_MAP.get(self.
_schedule_mode_schedule_mode, PRESET_RUN)
163 """Update the hold mode of the thermostat."""
165 PRESET_MODE_TO_SCHEDULE_MODE_MAP.get(preset_mode, SCHEDULE_RUN)
169 """Set a schedule mode."""
172 self.
_thermostat_thermostat.schedule_mode = schedule_mode
176 """Set a new target temperature."""
178 kwargs.get(ATTR_TEMPERATURE), hvac_mode=kwargs.get(ATTR_HVAC_MODE)
182 """Set temperature and hvac mode at the same time."""
184 target_temperature = celsius_to_nuheat(temperature)
186 target_temperature = fahrenheit_to_nuheat(temperature)
191 target_schedule_mode = SCHEDULE_TEMPORARY_HOLD
193 target_schedule_mode = PRESET_MODE_TO_SCHEDULE_MODE_MAP.get(
194 preset_mode, SCHEDULE_RUN
197 hvac_mode
and hvac_mode == HVACMode.HEAT
199 target_schedule_mode = SCHEDULE_HOLD
202 "Setting NuHeat thermostat temperature to %s %s and schedule mode: %s",
205 target_schedule_mode,
208 self.
_thermostat_thermostat.set_target_temperature(
209 target_temperature, target_schedule_mode
216 if not self.
hasshass:
226 event_helper.call_later(
231 """Force a refresh."""
232 await self.coordinator.async_refresh()
235 """When entity is added to hass."""
241 """Update our internal state from the last api response."""
247 """Get the latest state from the thermostat."""
253 """Return the device_info of the device."""
255 identifiers={(DOMAIN, self.
_thermostat_thermostat.serial_number)},
256 serial_number=self.
_thermostat_thermostat.serial_number,
258 model=
"nVent Signature",
259 manufacturer=MANUFACTURER,
str temperature_unit(self)
def _set_temperature_and_mode(self, temperature, hvac_mode=None, preset_mode=None)
def target_temperature(self)
None set_preset_mode(self, str preset_mode)
def __init__(self, coordinator, thermostat, temperature_unit)
str temperature_unit(self)
DeviceInfo device_info(self)
None async_added_to_hass(self)
def _set_schedule_mode(self, schedule_mode)
def _handle_coordinator_update(self)
def current_temperature(self)
HVACAction hvac_action(self)
def _update_internal_state(self)
None set_hvac_mode(self, HVACMode hvac_mode)
None set_temperature(self, **Any kwargs)
def _schedule_update(self)
None _forced_refresh(self, *_)
None async_write_ha_state(self)
None schedule_update_ha_state(self, bool force_refresh=False)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)