diff --git a/CODEOWNERS b/CODEOWNERS index e859a9d0eac..66332531bd8 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -131,6 +131,7 @@ homeassistant/components/growatt_server/* @indykoning homeassistant/components/gtfs/* @robbiet480 homeassistant/components/harmony/* @ehendrix23 homeassistant/components/hassio/* @home-assistant/hass-io +homeassistant/components/heatmiser/* @andylockran homeassistant/components/heos/* @andrewsayre homeassistant/components/here_travel_time/* @eifinger homeassistant/components/hikvision/* @mezz64 diff --git a/homeassistant/components/heatmiser/climate.py b/homeassistant/components/heatmiser/climate.py index 6693e71878a..1954749c21b 100644 --- a/homeassistant/components/heatmiser/climate.py +++ b/homeassistant/components/heatmiser/climate.py @@ -4,56 +4,62 @@ from typing import List import voluptuous as vol +from heatmiserV3 import heatmiser, connection from homeassistant.components.climate import ( ClimateDevice, PLATFORM_SCHEMA, HVAC_MODE_HEAT, + HVAC_MODE_OFF, ) from homeassistant.components.climate.const import SUPPORT_TARGET_TEMPERATURE from homeassistant.const import ( TEMP_CELSIUS, + TEMP_FAHRENHEIT, ATTR_TEMPERATURE, + CONF_HOST, CONF_PORT, - CONF_NAME, CONF_ID, + CONF_NAME, ) import homeassistant.helpers.config_validation as cv + _LOGGER = logging.getLogger(__name__) -CONF_IPADDRESS = "ipaddress" -CONF_TSTATS = "tstats" +CONF_THERMOSTATS = "tstats" TSTATS_SCHEMA = vol.Schema( - {vol.Required(CONF_ID): cv.string, vol.Required(CONF_NAME): cv.string} + vol.All( + cv.ensure_list, + [{vol.Required(CONF_ID): cv.positive_int, vol.Required(CONF_NAME): cv.string}], + ) ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend( { - vol.Required(CONF_IPADDRESS): cv.string, - vol.Required(CONF_PORT): cv.port, - vol.Required(CONF_TSTATS, default={}): vol.Schema({cv.string: TSTATS_SCHEMA}), + vol.Required(CONF_HOST): cv.string, + vol.Required(CONF_PORT): cv.string, + vol.Optional(CONF_THERMOSTATS, default=[]): TSTATS_SCHEMA, } ) def setup_platform(hass, config, add_entities, discovery_info=None): """Set up the heatmiser thermostat.""" - from heatmiserV3 import heatmiser, connection - ipaddress = config.get(CONF_IPADDRESS) - port = str(config.get(CONF_PORT)) - tstats = config.get(CONF_TSTATS) + heatmiser_v3_thermostat = heatmiser.HeatmiserThermostat - serport = connection.connection(ipaddress, port) - serport.open() + host = config[CONF_HOST] + port = config[CONF_PORT] + + thermostats = config[CONF_THERMOSTATS] + + uh1_hub = connection.HeatmiserUH1(host, port) add_entities( [ - HeatmiserV3Thermostat( - heatmiser, tstat.get(CONF_ID), tstat.get(CONF_NAME), serport - ) - for tstat in tstats.values() + HeatmiserV3Thermostat(heatmiser_v3_thermostat, thermostat, uh1_hub) + for thermostat in thermostats ], True, ) @@ -62,15 +68,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None): class HeatmiserV3Thermostat(ClimateDevice): """Representation of a HeatmiserV3 thermostat.""" - def __init__(self, heatmiser, device, name, serport): + def __init__(self, therm, device, uh1): """Initialize the thermostat.""" - self.heatmiser = heatmiser - self.serport = serport + self.therm = therm(device[CONF_ID], "prt", uh1) + self.uh1 = uh1 + self._name = device[CONF_NAME] self._current_temperature = None self._target_temperature = None - self._name = name self._id = device self.dcb = None + self._hvac_mode = HVAC_MODE_HEAT + self._temperature_unit = None @property def supported_features(self): @@ -85,7 +93,7 @@ class HeatmiserV3Thermostat(ClimateDevice): @property def temperature_unit(self): """Return the unit of measurement which this thermostat uses.""" - return TEMP_CELSIUS + return self._temperature_unit @property def hvac_mode(self) -> str: @@ -93,7 +101,7 @@ class HeatmiserV3Thermostat(ClimateDevice): Need to be one of HVAC_MODE_*. """ - return HVAC_MODE_HEAT + return self._hvac_mode @property def hvac_modes(self) -> List[str]: @@ -101,7 +109,7 @@ class HeatmiserV3Thermostat(ClimateDevice): Need to be a subset of HVAC_MODES. """ - return [HVAC_MODE_HEAT] + return [HVAC_MODE_HEAT, HVAC_MODE_OFF] @property def current_temperature(self): @@ -116,12 +124,25 @@ class HeatmiserV3Thermostat(ClimateDevice): def set_temperature(self, **kwargs): """Set new target temperature.""" temperature = kwargs.get(ATTR_TEMPERATURE) - self.heatmiser.hmSendAddress(self._id, 18, temperature, 1, self.serport) + self._target_temperature = int(temperature) + self.therm.set_target_temp(self._target_temperature) def update(self): """Get the latest data.""" - self.dcb = self.heatmiser.hmReadAddress(self._id, "prt", self.serport) - low = self.dcb.get("floortemplow ") - high = self.dcb.get("floortemphigh") - self._current_temperature = (high * 256 + low) / 10.0 - self._target_temperature = int(self.dcb.get("roomset")) + self.uh1.reopen() + if not self.uh1.status: + _LOGGER.error("Failed to update device %s", self._name) + return + self.dcb = self.therm.read_dcb() + self._temperature_unit = ( + TEMP_CELSIUS + if (self.therm.get_temperature_format() == "C") + else TEMP_FAHRENHEIT + ) + self._current_temperature = int(self.therm.get_floor_temp()) + self._target_temperature = int(self.therm.get_target_temp()) + self._hvac_mode = ( + HVAC_MODE_OFF + if (int(self.therm.get_current_state()) == 0) + else HVAC_MODE_HEAT + ) diff --git a/homeassistant/components/heatmiser/manifest.json b/homeassistant/components/heatmiser/manifest.json index b3882c63c51..89bcec08125 100644 --- a/homeassistant/components/heatmiser/manifest.json +++ b/homeassistant/components/heatmiser/manifest.json @@ -3,8 +3,10 @@ "name": "Heatmiser", "documentation": "https://www.home-assistant.io/integrations/heatmiser", "requirements": [ - "heatmiserV3==0.9.1" + "heatmiserV3==1.1.18" ], "dependencies": [], - "codeowners": [] -} + "codeowners": [ + "@andylockran" + ] +} \ No newline at end of file diff --git a/requirements_all.txt b/requirements_all.txt index 60b8dbb43ca..75fc2dd5bbd 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -643,7 +643,7 @@ hbmqtt==0.9.5 hdate==0.9.3 # homeassistant.components.heatmiser -heatmiserV3==0.9.1 +heatmiserV3==1.1.18 # homeassistant.components.here_travel_time herepy==0.6.3.3