Update heatmiserv3 integration (#29006)

* Updated heatmiserV3 initial commit

* Fixing heatmiser component

* Updated codeowners and heatmiserV3 version

* Updating files as part of PR process

* Removed extra _LOGGER statements.

* Added in HVAC_MODE_OFF to allowed states to track whether heating on/off

* Handling PR comments

* Removed legacy tests

* fixing pylint errors

* Update homeassistant/components/heatmiser/climate.py

Removed .get from config

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/heatmiser/climate.py

Removed .get from config

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/components/heatmiser/climate.py

Removed .get from config

Co-Authored-By: Martin Hjelmare <marhje52@gmail.com>

* Updated climate based on latest feedback

* Removed cast to int and update requirements

* Update requirements

* Updated heatmiser deps
This commit is contained in:
Andy Loughran 2019-12-03 05:48:51 +00:00 committed by Fabian Affolter
parent d5ee34e504
commit 434b783b4c
4 changed files with 58 additions and 34 deletions

View File

@ -131,6 +131,7 @@ homeassistant/components/growatt_server/* @indykoning
homeassistant/components/gtfs/* @robbiet480 homeassistant/components/gtfs/* @robbiet480
homeassistant/components/harmony/* @ehendrix23 homeassistant/components/harmony/* @ehendrix23
homeassistant/components/hassio/* @home-assistant/hass-io homeassistant/components/hassio/* @home-assistant/hass-io
homeassistant/components/heatmiser/* @andylockran
homeassistant/components/heos/* @andrewsayre homeassistant/components/heos/* @andrewsayre
homeassistant/components/here_travel_time/* @eifinger homeassistant/components/here_travel_time/* @eifinger
homeassistant/components/hikvision/* @mezz64 homeassistant/components/hikvision/* @mezz64

View File

@ -4,56 +4,62 @@ from typing import List
import voluptuous as vol import voluptuous as vol
from heatmiserV3 import heatmiser, connection
from homeassistant.components.climate import ( from homeassistant.components.climate import (
ClimateDevice, ClimateDevice,
PLATFORM_SCHEMA, PLATFORM_SCHEMA,
HVAC_MODE_HEAT, HVAC_MODE_HEAT,
HVAC_MODE_OFF,
) )
from homeassistant.components.climate.const import SUPPORT_TARGET_TEMPERATURE from homeassistant.components.climate.const import SUPPORT_TARGET_TEMPERATURE
from homeassistant.const import ( from homeassistant.const import (
TEMP_CELSIUS, TEMP_CELSIUS,
TEMP_FAHRENHEIT,
ATTR_TEMPERATURE, ATTR_TEMPERATURE,
CONF_HOST,
CONF_PORT, CONF_PORT,
CONF_NAME,
CONF_ID, CONF_ID,
CONF_NAME,
) )
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
CONF_IPADDRESS = "ipaddress" CONF_THERMOSTATS = "tstats"
CONF_TSTATS = "tstats"
TSTATS_SCHEMA = vol.Schema( 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( PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{ {
vol.Required(CONF_IPADDRESS): cv.string, vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_PORT): cv.port, vol.Required(CONF_PORT): cv.string,
vol.Required(CONF_TSTATS, default={}): vol.Schema({cv.string: TSTATS_SCHEMA}), vol.Optional(CONF_THERMOSTATS, default=[]): TSTATS_SCHEMA,
} }
) )
def setup_platform(hass, config, add_entities, discovery_info=None): def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the heatmiser thermostat.""" """Set up the heatmiser thermostat."""
from heatmiserV3 import heatmiser, connection
ipaddress = config.get(CONF_IPADDRESS) heatmiser_v3_thermostat = heatmiser.HeatmiserThermostat
port = str(config.get(CONF_PORT))
tstats = config.get(CONF_TSTATS)
serport = connection.connection(ipaddress, port) host = config[CONF_HOST]
serport.open() port = config[CONF_PORT]
thermostats = config[CONF_THERMOSTATS]
uh1_hub = connection.HeatmiserUH1(host, port)
add_entities( add_entities(
[ [
HeatmiserV3Thermostat( HeatmiserV3Thermostat(heatmiser_v3_thermostat, thermostat, uh1_hub)
heatmiser, tstat.get(CONF_ID), tstat.get(CONF_NAME), serport for thermostat in thermostats
)
for tstat in tstats.values()
], ],
True, True,
) )
@ -62,15 +68,17 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
class HeatmiserV3Thermostat(ClimateDevice): class HeatmiserV3Thermostat(ClimateDevice):
"""Representation of a HeatmiserV3 thermostat.""" """Representation of a HeatmiserV3 thermostat."""
def __init__(self, heatmiser, device, name, serport): def __init__(self, therm, device, uh1):
"""Initialize the thermostat.""" """Initialize the thermostat."""
self.heatmiser = heatmiser self.therm = therm(device[CONF_ID], "prt", uh1)
self.serport = serport self.uh1 = uh1
self._name = device[CONF_NAME]
self._current_temperature = None self._current_temperature = None
self._target_temperature = None self._target_temperature = None
self._name = name
self._id = device self._id = device
self.dcb = None self.dcb = None
self._hvac_mode = HVAC_MODE_HEAT
self._temperature_unit = None
@property @property
def supported_features(self): def supported_features(self):
@ -85,7 +93,7 @@ class HeatmiserV3Thermostat(ClimateDevice):
@property @property
def temperature_unit(self): def temperature_unit(self):
"""Return the unit of measurement which this thermostat uses.""" """Return the unit of measurement which this thermostat uses."""
return TEMP_CELSIUS return self._temperature_unit
@property @property
def hvac_mode(self) -> str: def hvac_mode(self) -> str:
@ -93,7 +101,7 @@ class HeatmiserV3Thermostat(ClimateDevice):
Need to be one of HVAC_MODE_*. Need to be one of HVAC_MODE_*.
""" """
return HVAC_MODE_HEAT return self._hvac_mode
@property @property
def hvac_modes(self) -> List[str]: def hvac_modes(self) -> List[str]:
@ -101,7 +109,7 @@ class HeatmiserV3Thermostat(ClimateDevice):
Need to be a subset of HVAC_MODES. Need to be a subset of HVAC_MODES.
""" """
return [HVAC_MODE_HEAT] return [HVAC_MODE_HEAT, HVAC_MODE_OFF]
@property @property
def current_temperature(self): def current_temperature(self):
@ -116,12 +124,25 @@ class HeatmiserV3Thermostat(ClimateDevice):
def set_temperature(self, **kwargs): def set_temperature(self, **kwargs):
"""Set new target temperature.""" """Set new target temperature."""
temperature = kwargs.get(ATTR_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): def update(self):
"""Get the latest data.""" """Get the latest data."""
self.dcb = self.heatmiser.hmReadAddress(self._id, "prt", self.serport) self.uh1.reopen()
low = self.dcb.get("floortemplow ") if not self.uh1.status:
high = self.dcb.get("floortemphigh") _LOGGER.error("Failed to update device %s", self._name)
self._current_temperature = (high * 256 + low) / 10.0 return
self._target_temperature = int(self.dcb.get("roomset")) 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
)

View File

@ -3,8 +3,10 @@
"name": "Heatmiser", "name": "Heatmiser",
"documentation": "https://www.home-assistant.io/integrations/heatmiser", "documentation": "https://www.home-assistant.io/integrations/heatmiser",
"requirements": [ "requirements": [
"heatmiserV3==0.9.1" "heatmiserV3==1.1.18"
], ],
"dependencies": [], "dependencies": [],
"codeowners": [] "codeowners": [
"@andylockran"
]
} }

View File

@ -643,7 +643,7 @@ hbmqtt==0.9.5
hdate==0.9.3 hdate==0.9.3
# homeassistant.components.heatmiser # homeassistant.components.heatmiser
heatmiserV3==0.9.1 heatmiserV3==1.1.18
# homeassistant.components.here_travel_time # homeassistant.components.here_travel_time
herepy==0.6.3.3 herepy==0.6.3.3