mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Use voluptuous for Heatmiser (#3732)
This commit is contained in:
parent
8ded8f572a
commit
0568ef025b
@ -1,56 +1,54 @@
|
|||||||
"""
|
"""
|
||||||
Support for the PRT Heatmiser themostats using the V3 protocol.
|
Support for the PRT Heatmiser themostats using the V3 protocol.
|
||||||
|
|
||||||
See https://github.com/andylockran/heatmiserV3 for more info on the
|
|
||||||
heatmiserV3 module dependency.
|
|
||||||
|
|
||||||
For more details about this platform, please refer to the documentation at
|
For more details about this platform, please refer to the documentation at
|
||||||
https://home-assistant.io/components/climate.heatmiser/
|
https://home-assistant.io/components/climate.heatmiser/
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.components.climate import ClimateDevice
|
import voluptuous as vol
|
||||||
from homeassistant.const import TEMP_CELSIUS, ATTR_TEMPERATURE
|
|
||||||
|
|
||||||
CONF_IPADDRESS = 'ipaddress'
|
from homeassistant.components.climate import ClimateDevice, PLATFORM_SCHEMA
|
||||||
CONF_PORT = 'port'
|
from homeassistant.const import (
|
||||||
CONF_TSTATS = 'tstats'
|
TEMP_CELSIUS, ATTR_TEMPERATURE, CONF_PORT, CONF_NAME, CONF_ID)
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
|
||||||
REQUIREMENTS = ["heatmiserV3==0.9.1"]
|
REQUIREMENTS = ['heatmiserV3==0.9.1']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
CONF_IPADDRESS = 'ipaddress'
|
||||||
|
CONF_TSTATS = 'tstats'
|
||||||
|
|
||||||
|
TSTATS_SCHEMA = vol.Schema({
|
||||||
|
vol.Required(CONF_ID): cv.string,
|
||||||
|
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}),
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
# pylint: disable=unused-variable
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Setup the heatmiser thermostat."""
|
"""Setup the heatmiser thermostat."""
|
||||||
from heatmiserV3 import heatmiser, connection
|
from heatmiserV3 import heatmiser, connection
|
||||||
|
|
||||||
ipaddress = str(config[CONF_IPADDRESS])
|
ipaddress = config.get(CONF_IPADDRESS)
|
||||||
port = str(config[CONF_PORT])
|
port = str(config.get(CONF_PORT))
|
||||||
|
tstats = config.get(CONF_TSTATS)
|
||||||
if ipaddress is None or port is None:
|
|
||||||
_LOGGER.error("Missing required configuration items %s or %s",
|
|
||||||
CONF_IPADDRESS, CONF_PORT)
|
|
||||||
return False
|
|
||||||
|
|
||||||
serport = connection.connection(ipaddress, port)
|
serport = connection.connection(ipaddress, port)
|
||||||
serport.open()
|
serport.open()
|
||||||
|
|
||||||
tstats = []
|
for thermostat, tstat in tstats.items():
|
||||||
if CONF_TSTATS in config:
|
|
||||||
tstats = config[CONF_TSTATS]
|
|
||||||
|
|
||||||
if tstats is None:
|
|
||||||
_LOGGER.error("No thermostats configured.")
|
|
||||||
return False
|
|
||||||
|
|
||||||
for tstat in tstats:
|
|
||||||
add_devices([
|
add_devices([
|
||||||
HeatmiserV3Thermostat(
|
HeatmiserV3Thermostat(
|
||||||
heatmiser,
|
heatmiser, tstat.get(CONF_ID), tstat.get(CONF_NAME), serport)
|
||||||
tstat.get("id"),
|
|
||||||
tstat.get("name"),
|
|
||||||
serport)
|
|
||||||
])
|
])
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -69,7 +67,7 @@ class HeatmiserV3Thermostat(ClimateDevice):
|
|||||||
self._id = device
|
self._id = device
|
||||||
self.dcb = None
|
self.dcb = None
|
||||||
self.update()
|
self.update()
|
||||||
self._target_temperature = int(self.dcb.get("roomset"))
|
self._target_temperature = int(self.dcb.get('roomset'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -85,9 +83,9 @@ class HeatmiserV3Thermostat(ClimateDevice):
|
|||||||
def current_temperature(self):
|
def current_temperature(self):
|
||||||
"""Return the current temperature."""
|
"""Return the current temperature."""
|
||||||
if self.dcb is not None:
|
if self.dcb is not None:
|
||||||
low = self.dcb.get("floortemplow ")
|
low = self.dcb.get('floortemplow ')
|
||||||
high = self.dcb.get("floortemphigh")
|
high = self.dcb.get('floortemphigh')
|
||||||
temp = (high*256 + low)/10.0
|
temp = (high * 256 + low) / 10.0
|
||||||
self._current_temperature = temp
|
self._current_temperature = temp
|
||||||
else:
|
else:
|
||||||
self._current_temperature = None
|
self._current_temperature = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user