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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update heatmiserv3 integration #29006

Merged
merged 18 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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
Expand Down
78 changes: 48 additions & 30 deletions homeassistant/components/heatmiser/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,59 @@

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.Required(CONF_ID): cv.string, vol.Required(CONF_NAME): cv.string}]
andylockran marked this conversation as resolved.
Show resolved Hide resolved
)

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,
andylockran marked this conversation as resolved.
Show resolved Hide resolved
}
)


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

host = config.get(CONF_HOST)
andylockran marked this conversation as resolved.
Show resolved Hide resolved
port = config.get(CONF_PORT)
andylockran marked this conversation as resolved.
Show resolved Hide resolved

serport = connection.connection(ipaddress, port)
serport.open()
thermostats = config.get(CONF_THERMOSTATS)
andylockran marked this conversation as resolved.
Show resolved Hide resolved

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,
)
Expand All @@ -62,15 +65,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(int(device[CONF_ID]), "prt", uh1)
MartinHjelmare marked this conversation as resolved.
Show resolved Hide resolved
andylockran marked this conversation as resolved.
Show resolved Hide resolved
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):
Expand All @@ -85,23 +90,23 @@ def name(self):
@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:
"""Return hvac operation ie. heat, cool mode.

Need to be one of HVAC_MODE_*.
"""
return HVAC_MODE_HEAT
return self._hvac_mode

@property
def hvac_modes(self) -> List[str]:
"""Return the list of available hvac operation modes.

Need to be a subset of HVAC_MODES.
"""
return [HVAC_MODE_HEAT]
return [HVAC_MODE_HEAT, HVAC_MODE_OFF]

@property
def current_temperature(self):
Expand All @@ -116,12 +121,25 @@ def target_temperature(self):
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 self.uh1.status is not True:
andylockran marked this conversation as resolved.
Show resolved Hide resolved
_LOGGER.error("Failed to update device %s", self._name)
else:
andylockran marked this conversation as resolved.
Show resolved Hide resolved
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
)
6 changes: 2 additions & 4 deletions homeassistant/components/heatmiser/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
"domain": "heatmiser",
"name": "Heatmiser",
"documentation": "https://www.home-assistant.io/integrations/heatmiser",
"requirements": [
"heatmiserV3==0.9.1"
],
"requirements": ["heatmiserV3==1.1.11"],
"dependencies": [],
"codeowners": []
"codeowners": ["@andylockran"]
}
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ hbmqtt==0.9.5
hdate==0.9.3

# homeassistant.components.heatmiser
heatmiserV3==0.9.1
heatmiserV3==1.1.11
andylockran marked this conversation as resolved.
Show resolved Hide resolved

# homeassistant.components.here_travel_time
herepy==0.6.3.3
Expand Down