Rewrite opentherm_gw to a component which loads the opentherm_gw climate platform.
parent
22a80cf733
commit
442bc0f75b
|
@ -12,24 +12,18 @@ from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA,
|
|||
STATE_IDLE, STATE_HEAT,
|
||||
STATE_COOL,
|
||||
SUPPORT_TARGET_TEMPERATURE)
|
||||
from homeassistant.components.opentherm_gw import SIGNAL_OPENTHERM_GW_UPDATE
|
||||
from homeassistant.const import (ATTR_TEMPERATURE, CONF_DEVICE, CONF_NAME,
|
||||
PRECISION_HALVES, PRECISION_TENTHS,
|
||||
TEMP_CELSIUS, PRECISION_WHOLE)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['pyotgw==0.1b0']
|
||||
DEPENDENCIES = ['opentherm_gw']
|
||||
|
||||
CONF_FLOOR_TEMP = "floor_temperature"
|
||||
CONF_PRECISION = 'precision'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_DEVICE): cv.string,
|
||||
vol.Optional(CONF_NAME, default="OpenTherm Gateway"): cv.string,
|
||||
vol.Optional(CONF_PRECISION): vol.In([PRECISION_TENTHS, PRECISION_HALVES,
|
||||
PRECISION_WHOLE]),
|
||||
vol.Optional(CONF_FLOOR_TEMP, default=False): cv.boolean,
|
||||
})
|
||||
|
||||
SUPPORT_FLAGS = (SUPPORT_TARGET_TEMPERATURE)
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -37,7 +31,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
async def async_setup_platform(hass, config, async_add_entities,
|
||||
discovery_info=None):
|
||||
"""Set up the opentherm_gw device."""
|
||||
gateway = OpenThermGateway(config)
|
||||
gateway = OpenThermGateway(discovery_info)
|
||||
async_add_entities([gateway])
|
||||
|
||||
|
||||
|
@ -45,11 +39,9 @@ class OpenThermGateway(ClimateDevice):
|
|||
"""Representation of a climate device."""
|
||||
|
||||
def __init__(self, config):
|
||||
"""Initialize the sensor."""
|
||||
"""Initialize the device."""
|
||||
import pyotgw
|
||||
self.pyotgw = pyotgw
|
||||
self.gateway = self.pyotgw.pyotgw()
|
||||
self._device = config[CONF_DEVICE]
|
||||
self.friendly_name = config.get(CONF_NAME)
|
||||
self.floor_temp = config.get(CONF_FLOOR_TEMP)
|
||||
self.temp_precision = config.get(CONF_PRECISION)
|
||||
|
@ -63,10 +55,9 @@ class OpenThermGateway(ClimateDevice):
|
|||
|
||||
async def async_added_to_hass(self):
|
||||
"""Connect to the OpenTherm Gateway device."""
|
||||
await self.gateway.connect(self.hass.loop, self._device)
|
||||
self.gateway.subscribe(self.receive_report)
|
||||
_LOGGER.debug("Connected to %s on %s", self.friendly_name,
|
||||
self._device)
|
||||
_LOGGER.debug("Added device {}".format(self.friendly_name))
|
||||
async_dispatcher_connect(self.hass, SIGNAL_OPENTHERM_GW_UPDATE,
|
||||
self.receive_report)
|
||||
|
||||
async def receive_report(self, status):
|
||||
"""Receive and handle a new report from the Gateway."""
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
import asyncio
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers.discovery import (async_load_platform,
|
||||
async_listen_platform)
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.const import (CONF_BINARY_SENSORS, CONF_DEVICE,
|
||||
CONF_MONITORED_VARIABLES, CONF_NAME,
|
||||
CONF_SENSORS, PRECISION_HALVES,
|
||||
PRECISION_TENTHS, PRECISION_WHOLE)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
DOMAIN = 'opentherm_gw'
|
||||
|
||||
CONF_CLIMATE = 'climate'
|
||||
CONF_FLOOR_TEMP = 'floor_temperature'
|
||||
CONF_PRECISION = 'precision'
|
||||
|
||||
SIGNAL_OPENTHERM_GW_UPDATE = 'opentherm_gw_update'
|
||||
|
||||
CLIMATE_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_NAME, default="OpenTherm Gateway"): cv.string,
|
||||
vol.Optional(CONF_PRECISION): vol.In([PRECISION_TENTHS, PRECISION_HALVES,
|
||||
PRECISION_WHOLE]),
|
||||
vol.Optional(CONF_FLOOR_TEMP, default=False): cv.boolean,
|
||||
})
|
||||
|
||||
SENSOR_SCHEMA = vol.Schema({
|
||||
vol.Optional(CONF_MONITORED_VARIABLES, default=[]): cv.ensure_list,
|
||||
})
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_DEVICE): cv.string,
|
||||
vol.Optional(CONF_CLIMATE, default=CLIMATE_SCHEMA({})):
|
||||
CLIMATE_SCHEMA,
|
||||
vol.Optional(CONF_SENSORS, default=SENSOR_SCHEMA({})): SENSOR_SCHEMA,
|
||||
vol.Optional(CONF_BINARY_SENSORS, default=SENSOR_SCHEMA({})):
|
||||
SENSOR_SCHEMA,
|
||||
}),
|
||||
}, extra = vol.ALLOW_EXTRA)
|
||||
|
||||
REQUIREMENTS = ['pyotgw==0.1b0']
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Set up the OpenTherm Gateway component."""
|
||||
conf = config.get(DOMAIN)
|
||||
if conf is None:
|
||||
return True
|
||||
|
||||
hass.async_add_job(connect_and_subscribe, hass, conf)
|
||||
hass.async_create_task(async_load_platform(
|
||||
hass, 'climate', DOMAIN, conf.get(CONF_CLIMATE)))
|
||||
#hass.async_create_task(async_load_platform(
|
||||
# hass, 'sensor', DOMAIN, conf.get(CONF_MONITORED_VARIABLES)))
|
||||
#hass.async_create_task(async_load_platform(
|
||||
# hass, 'binary_sensor', DOMAIN, conf.get(CONF_MONITORED_VARIABLES)))
|
||||
return True
|
||||
|
||||
async def connect_and_subscribe(hass, conf):
|
||||
"""Connect to serial device and subscribe report handler."""
|
||||
import pyotgw
|
||||
gateway = pyotgw.pyotgw()
|
||||
await gateway.connect(hass.loop, conf[CONF_DEVICE])
|
||||
|
||||
async def handle_report(status):
|
||||
"""Handle reports from the OpenTherm Gateway."""
|
||||
async_dispatcher_send(hass, SIGNAL_OPENTHERM_GW_UPDATE, status)
|
||||
gateway.subscribe(handle_report)
|
||||
|
||||
|
||||
# class OpenThermSensor(Entity):
|
||||
# """Basic functionality for opentherm_gw sensor."""
|
||||
#
|
Loading…
Reference in New Issue