From 27827d7f24a808df1928f8255c79829bc1cde155 Mon Sep 17 00:00:00 2001 From: tjdavisbz Date: Tue, 13 Apr 2021 00:01:44 -0500 Subject: [PATCH] Added support for unique id --- custom_components/infinitive/climate.py | 232 +++++++++++---------- custom_components/infinitive/manifest.json | 4 +- 2 files changed, 129 insertions(+), 107 deletions(-) diff --git a/custom_components/infinitive/climate.py b/custom_components/infinitive/climate.py index 1917329..a2ddb25 100644 --- a/custom_components/infinitive/climate.py +++ b/custom_components/infinitive/climate.py @@ -1,4 +1,3 @@ - """ Infinitive support for Home Assistant. @@ -11,42 +10,62 @@ import voluptuous as vol import logging +from voluptuous.schema_builder import _iterate_mapping_candidates + import homeassistant.helpers.config_validation as cv -from homeassistant.const import CONF_FILENAME, CONF_HOST, CONF_PORT, \ - TEMP_CELSIUS, TEMP_FAHRENHEIT, ATTR_FRIENDLY_NAME -from homeassistant.components.climate import ClimateEntity, PLATFORM_SCHEMA, \ - ATTR_TEMPERATURE - -from homeassistant.components.climate.const import ATTR_CURRENT_TEMPERATURE, \ - ATTR_CURRENT_HUMIDITY, ATTR_FAN_MODE, ATTR_FAN_MODES, \ - ATTR_HVAC_MODE, ATTR_HVAC_MODES, ATTR_TARGET_TEMP_HIGH, \ - ATTR_TARGET_TEMP_LOW, HVAC_MODES, PRESET_HOME, FAN_AUTO, FAN_LOW, \ - FAN_MEDIUM, FAN_HIGH, CURRENT_HVAC_COOL, \ - CURRENT_HVAC_HEAT, CURRENT_HVAC_IDLE, \ - SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE, \ - SUPPORT_FAN_MODE, SUPPORT_PRESET_MODE +from homeassistant.const import ( + CONF_FILENAME, + CONF_HOST, + CONF_PORT, + TEMP_CELSIUS, + TEMP_FAHRENHEIT, + ATTR_FRIENDLY_NAME, +) +from homeassistant.components.climate import ( + ClimateEntity, + PLATFORM_SCHEMA, + ATTR_TEMPERATURE, +) + +from homeassistant.components.climate.const import ( + ATTR_CURRENT_TEMPERATURE, + ATTR_CURRENT_HUMIDITY, + ATTR_FAN_MODE, + ATTR_FAN_MODES, + ATTR_HVAC_MODE, + ATTR_HVAC_MODES, + ATTR_TARGET_TEMP_HIGH, + ATTR_TARGET_TEMP_LOW, + HVAC_MODES, + PRESET_HOME, + FAN_AUTO, + FAN_LOW, + FAN_MEDIUM, + FAN_HIGH, + CURRENT_HVAC_COOL, + CURRENT_HVAC_HEAT, + CURRENT_HVAC_IDLE, + SUPPORT_TARGET_TEMPERATURE, + SUPPORT_TARGET_TEMPERATURE_RANGE, + SUPPORT_FAN_MODE, + SUPPORT_PRESET_MODE, +) _LOGGER = logging.getLogger(__name__) DOMAIN = "infinitive" -SUPPORT_FLAGS_BASE = SUPPORT_FAN_MODE | \ - SUPPORT_PRESET_MODE -CONF_TEMP_UNITS = 'TempUnits' -CONF_TEMP_MIN_SPREAD = 'tempminspread' +SUPPORT_FLAGS_BASE = SUPPORT_FAN_MODE | SUPPORT_PRESET_MODE +CONF_TEMP_UNITS = "TempUnits" +CONF_TEMP_MIN_SPREAD = "tempminspread" """ tempminspread (Temperature Minimum Spread) refers to the minimum allowed range between high and low temperatures. For instance, if tempminspread is 4 and the high temp is 72F the low temp can be no warmer than 68F. """ -ATTR_STAGE = 'stage' -ATTR_BLOWER_RPM = 'blower_rpm' -ATTR_AIRFLOW_CFM = 'airflow_cfm' +ATTR_STAGE = "stage" +ATTR_BLOWER_RPM = "blower_rpm" +ATTR_AIRFLOW_CFM = "airflow_cfm" ATTR_FAN_MODES = [FAN_AUTO, FAN_LOW, FAN_MEDIUM, FAN_HIGH] -FAN_MODE_MAP = { - 'auto': FAN_AUTO, - 'low': FAN_LOW, - 'med': FAN_MEDIUM, - 'high': FAN_HIGH -} +FAN_MODE_MAP = {"auto": FAN_AUTO, "low": FAN_LOW, "med": FAN_MEDIUM, "high": FAN_HIGH} # ATTR_OPERATION_LIST = ['auto', 'cool', 'heat', 'off'] """ The override duration refers to a deviation from the current schedule. @@ -57,22 +76,24 @@ The default override time is 120 minutes. """ -ATTR_OVERRIDE_DURATION = 'override_duration' -ATTR_OUTDOOR_TEMP = 'outdoor_temp' -ATTR_AUX_HEAT = 'aux_heat' -ATTR_HEATPUMP_COIL_TEMP = 'heatpump_coil_temp' -ATTR_HEATPUMP_OUTSIDE_TEMP = 'heatpump_outside_temp' -ATTR_HEATPUMP_STAGE = 'heatpump_stage' -ATTR_TARGET_HUMIDITY = 'target_humidity' -PRESET_HOLD = 'Hold' - -PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ - vol.Required(CONF_HOST): cv.string, - vol.Required(CONF_PORT, default=8080): cv.positive_int, - vol.Optional(ATTR_FRIENDLY_NAME, default='Infinitive'): cv.string, - vol.Optional(CONF_TEMP_UNITS, default=TEMP_FAHRENHEIT): cv.string, - vol.Optional(CONF_TEMP_MIN_SPREAD, default=2): cv.positive_int -}) +ATTR_OVERRIDE_DURATION = "override_duration" +ATTR_OUTDOOR_TEMP = "outdoor_temp" +ATTR_AUX_HEAT = "aux_heat" +ATTR_HEATPUMP_COIL_TEMP = "heatpump_coil_temp" +ATTR_HEATPUMP_OUTSIDE_TEMP = "heatpump_outside_temp" +ATTR_HEATPUMP_STAGE = "heatpump_stage" +ATTR_TARGET_HUMIDITY = "target_humidity" +PRESET_HOLD = "Hold" + +PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( + { + vol.Required(CONF_HOST): cv.string, + vol.Required(CONF_PORT, default=8080): cv.positive_int, + vol.Optional(ATTR_FRIENDLY_NAME, default="Infinitive"): cv.string, + vol.Optional(CONF_TEMP_UNITS, default=TEMP_FAHRENHEIT): cv.string, + vol.Optional(CONF_TEMP_MIN_SPREAD, default=2): cv.positive_int, + } +) def setup_platform(hass, config, add_entities, discovery_info=None): @@ -83,22 +104,20 @@ def setup_platform(hass, config, add_entities, discovery_info=None): host = config[CONF_HOST] port = config[CONF_PORT] name = config[ATTR_FRIENDLY_NAME] + uniqueid = config[CONF_HOST] + ":" + str(config[CONF_PORT]) temp_units = config[CONF_TEMP_UNITS] temp_min_spread = config[CONF_TEMP_MIN_SPREAD] - inf_device = pyinfinitive.infinitive_device( - host, - port, - temp_units) + inf_device = pyinfinitive.infinitive_device(host, port, temp_units) _LOGGER.debug("Adding Infinitive device") - add_entities([InfinitiveDevice(inf_device, name, temp_min_spread)]) + add_entities([InfinitiveDevice(inf_device, name, temp_min_spread, uniqueid)]) class InfinitiveDevice(ClimateEntity): """Representation of an Infinitive Device.""" - def __init__(self, inf_device, name, temp_min_spread): + def __init__(self, inf_device, name, temp_min_spread, uniqueid): """Initialize Infinitive device instance.""" _LOGGER.debug("Initializing infinitive class instance") self._inf_device = inf_device @@ -127,21 +146,26 @@ def __init__(self, inf_device, name, temp_min_spread): self._heatpump_outside_temp = None self._heatpump_stage = None self._hvac_action = None + self._unique_id = uniqueid + self.update() @property def supported_features(self): """Return list of supported features.""" - if self._hvac_mode == 'cool' or self._hvac_mode == 'heat': - self._support_flags = SUPPORT_FLAGS_BASE | \ - SUPPORT_TARGET_TEMPERATURE + if self._hvac_mode == "cool" or self._hvac_mode == "heat": + self._support_flags = SUPPORT_FLAGS_BASE | SUPPORT_TARGET_TEMPERATURE _LOGGER.debug("Support Flags: " + str(self._support_flags)) else: - self._support_flags = SUPPORT_FLAGS_BASE | \ - SUPPORT_TARGET_TEMPERATURE_RANGE + self._support_flags = SUPPORT_FLAGS_BASE | SUPPORT_TARGET_TEMPERATURE_RANGE _LOGGER.debug("Support Flags: " + str(self._support_flags)) return self._support_flags + @property + def unique_id(self): + """Return the unique id of this alarm control panel.""" + return self._unique_id + @property def name(self): """Return the name of the infinitive device.""" @@ -156,22 +180,19 @@ def current_temperature(self): @property def target_temperature_high(self): """Return the target high temp(cool setpoint).""" - _LOGGER.debug("Target High Temp: " + - str(self._target_temperature_high)) + _LOGGER.debug("Target High Temp: " + str(self._target_temperature_high)) return self._target_temperature_high @property def target_temperature_low(self): """Return the target low temp(heat setpoint).""" - _LOGGER.debug("Target Low Temp: " + - str(self._target_temperature_low)) + _LOGGER.debug("Target Low Temp: " + str(self._target_temperature_low)) return self._target_temperature_low @property def target_temperature(self): """Return the target low temp(heat setpoint).""" - _LOGGER.debug("Target Temp: " + - str(self._target_temperature)) + _LOGGER.debug("Target Temp: " + str(self._target_temperature)) return self._target_temperature @property @@ -202,7 +223,7 @@ def fan_modes(self): @property def preset_mode(self): """Return current preset mode.""" - if self._status['hold'] is True: + if self._status["hold"] is True: return PRESET_HOLD else: return PRESET_HOME @@ -227,18 +248,18 @@ def device_state_attributes(self): ATTR_AUX_HEAT: self._aux_heat, ATTR_HEATPUMP_COIL_TEMP: self._heatpump_coil_temp, ATTR_HEATPUMP_OUTSIDE_TEMP: self._heatpump_outside_temp, - ATTR_HEATPUMP_STAGE: self._heatpump_stage + ATTR_HEATPUMP_STAGE: self._heatpump_stage, } @property def hvac_mode(self): """Return current hvac mode.""" - _LOGGER.debug("Getting HVAC Mode: " + str(self._status['mode'])) - if self._status['mode'] == 'cool': + _LOGGER.debug("Getting HVAC Mode: " + str(self._status["mode"])) + if self._status["mode"] == "cool": return HVAC_MODES[2] - elif self._status['mode'] == 'heat': + elif self._status["mode"] == "heat": return HVAC_MODES[1] - elif self._status['mode'] == 'auto': + elif self._status["mode"] == "auto": return HVAC_MODES[3] @property @@ -255,36 +276,36 @@ def update(self): """Update current status from infinitive device.""" _LOGGER.debug("Updating Infinitive status") status = self._inf_device.get_status() - if 'mode' in status.keys(): + if "mode" in status.keys(): self._status = status try: - self._hvac_mode = self._status['mode'] - self._target_temperature_high = self._status['coolSetpoint'] - self._target_temperature_low = self._status['heatSetpoint'] - if self._hvac_mode == 'cool': + self._hvac_mode = self._status["mode"] + self._target_temperature_high = self._status["coolSetpoint"] + self._target_temperature_low = self._status["heatSetpoint"] + if self._hvac_mode == "cool": self._target_temperature = self._target_temperature_high - elif self._hvac_mode == 'heat': + elif self._hvac_mode == "heat": self._target_temperature = self._target_temperature_low - self._target_humidity = self._status['targetHumidity'] - self._current_temperature = self._status['currentTemp'] - self._current_humidity = self._status['currentHumidity'] - self._blower_rpm = self._status['blowerRPM'] - self._fan_mode = FAN_MODE_MAP[self._status['fanMode']] - if self._status['hold'] is True: + self._target_humidity = self._status["targetHumidity"] + self._current_temperature = self._status["currentTemp"] + self._current_humidity = self._status["currentHumidity"] + self._blower_rpm = self._status["blowerRPM"] + self._fan_mode = FAN_MODE_MAP[self._status["fanMode"]] + if self._status["hold"] is True: self._preset_mode == PRESET_HOLD else: self._preset_mode == PRESET_HOME - self._stage = self._status['stage'] - self._override_duration = self._status['holdDurationMins'] - self._airflow_cfm = self._status['airFlowCFM'] - self._outdoor_temp = self._status['outdoorTemp'] - self._aux_heat = self._status['auxHeat'] - self._heatpump_coil_temp = self._status['heatpump_coilTemp'] - self._heatpump_outside_temp = self._status['heatpump_outsideTemp'] - self._heatpump_stage = self._status['heatpump_stage'] - if self._hvac_mode == 'cool' and self._stage > 0: + self._stage = self._status["stage"] + self._override_duration = self._status["holdDurationMins"] + self._airflow_cfm = self._status["airFlowCFM"] + self._outdoor_temp = self._status["outdoorTemp"] + self._aux_heat = self._status["auxHeat"] + self._heatpump_coil_temp = self._status["heatpump_coilTemp"] + self._heatpump_outside_temp = self._status["heatpump_outsideTemp"] + self._heatpump_stage = self._status["heatpump_stage"] + if self._hvac_mode == "cool" and self._stage > 0: self._hvac_action = CURRENT_HVAC_COOL - elif self._hvac_mode == 'heat' and self._stage > 0: + elif self._hvac_mode == "heat" and self._stage > 0: self._hvac_action = CURRENT_HVAC_HEAT else: self._hvac_action = CURRENT_HVAC_IDLE @@ -294,33 +315,36 @@ def update(self): def _set_temperature_high(self, cool_setpoint): """Set new coolpoint target temperature.""" _LOGGER.debug("Setting High Temp :" + str(cool_setpoint)) - self._inf_device.set_temp(int(cool_setpoint), 'cool') + self._inf_device.set_temp(int(cool_setpoint), "cool") def _set_temperature_low(self, heat_setpoint): """Set new heatpoint target temperature.""" _LOGGER.debug("Setting Low Temp :" + str(heat_setpoint)) - self._inf_device.set_temp(int(heat_setpoint), 'heat') + self._inf_device.set_temp(int(heat_setpoint), "heat") def set_temperature(self, **kwargs): """Set new target temperature.""" _LOGGER.debug("TempMinSpread: " + str(self._temp_min_spread)) - if self._hvac_mode == 'auto': + if self._hvac_mode == "auto": temperature_high = kwargs.get(ATTR_TARGET_TEMP_HIGH) temperature_low = kwargs.get(ATTR_TARGET_TEMP_LOW) if temperature_high - temperature_low < self._temp_min_spread: temperature_low = temperature_high - self._temp_min_spread self._set_temperature_high(temperature_high) self._set_temperature_low(temperature_low) - _LOGGER.debug("Setting new target temperature: " + - str(temperature_high) + " " + str(temperature_low)) + _LOGGER.debug( + "Setting new target temperature: " + + str(temperature_high) + + " " + + str(temperature_low) + ) else: temperature = kwargs.get(ATTR_TEMPERATURE) - if self._hvac_mode == 'cool': + if self._hvac_mode == "cool": self._set_temperature_high(temperature) - elif self._hvac_mode == 'heat': + elif self._hvac_mode == "heat": self._set_temperature_low(temperature) - _LOGGER.debug("Setting new target temperature: " + - str(temperature)) + _LOGGER.debug("Setting new target temperature: " + str(temperature)) def set_fan_mode(self, fan_mode): """Set new fan mode.""" @@ -328,7 +352,7 @@ def set_fan_mode(self, fan_mode): if fan_mode is None: return if fan_mode == FAN_MEDIUM: - self._inf_device.set_fanmode('med') + self._inf_device.set_fanmode("med") else: self._inf_device.set_fanmode(fan_mode) @@ -338,17 +362,15 @@ def set_hvac_mode(self, hvac_mode): if hvac_mode is None: return elif hvac_mode == HVAC_MODES[3]: - self._inf_device.set_mode('auto') - self._support_flags = SUPPORT_FLAGS_BASE | \ - SUPPORT_TARGET_TEMPERATURE_RANGE + self._inf_device.set_mode("auto") + self._support_flags = SUPPORT_FLAGS_BASE | SUPPORT_TARGET_TEMPERATURE_RANGE else: self._inf_device.set_mode(hvac_mode) - self._support_flags = SUPPORT_FLAGS_BASE | \ - SUPPORT_TARGET_TEMPERATURE + self._support_flags = SUPPORT_FLAGS_BASE | SUPPORT_TARGET_TEMPERATURE def set_preset_mode(self, mode): """Set new preset mode.""" - if mode == 'hold': + if mode == "hold": self._inf_device.set_hold(True) - elif mode == 'home': + elif mode == "home": self._inf_device.set_hold(False) diff --git a/custom_components/infinitive/manifest.json b/custom_components/infinitive/manifest.json index 5846fa1..63a96ad 100644 --- a/custom_components/infinitive/manifest.json +++ b/custom_components/infinitive/manifest.json @@ -4,6 +4,6 @@ "documentation": "https://github.com/mww012/ha_customcomponents", "requirements": ["pyinfinitive==0.0.5"], "dependencies": [], - "codeowners": ["@mww012"], - "version": "0.0.5" + "codeowners": ["@mww012","@tjdavisbz"], + "version": "0.0.6" }