Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite opentherm_gw to a component (#17133)
* Rewrite opentherm_gw to a component which loads the opentherm_gw climate platform. * Add OpenTherm Gateway sensor platform. * Remove library imports from platforms (use hass.data instead) * Update .coveragerc * Update docstrings to use new component documentation url * Add OpenTherm Gateway binary sensor support. Fix houndci findings. * Revert "Add OpenTherm Gateway binary sensor support." This reverts commit 5711dc4. * Revert "Add OpenTherm Gateway sensor platform." This reverts commit b3505ed. * Remove import from platform, use hass.data instead. Update .coveragerc Update docstrings Update requirements_all.txt General code cleanup * Fix review findings. Avoid using hass.data within connect_and_subscribe.
- Loading branch information
1 parent
2aeb0ef
commit fc67f5e
Showing
4 changed files
with
111 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
Support for OpenTherm Gateway devices. | ||
For more details about this component, please refer to the documentation at | ||
http://home-assistant.io/components/opentherm_gw/ | ||
""" | ||
import logging | ||
|
||
import voluptuous as vol | ||
|
||
from homeassistant.const import (CONF_DEVICE, CONF_NAME, PRECISION_HALVES, | ||
PRECISION_TENTHS, PRECISION_WHOLE) | ||
from homeassistant.helpers.discovery import async_load_platform | ||
from homeassistant.helpers.dispatcher import async_dispatcher_send | ||
|
||
import homeassistant.helpers.config_validation as cv | ||
|
||
DOMAIN = 'opentherm_gw' | ||
|
||
CONF_CLIMATE = 'climate' | ||
CONF_FLOOR_TEMP = 'floor_temperature' | ||
CONF_PRECISION = 'precision' | ||
|
||
DATA_DEVICE = 'device' | ||
DATA_GW_VARS = 'gw_vars' | ||
DATA_OPENTHERM_GW = 'opentherm_gw' | ||
|
||
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, | ||
}) | ||
|
||
CONFIG_SCHEMA = vol.Schema({ | ||
DOMAIN: vol.Schema({ | ||
vol.Required(CONF_DEVICE): cv.string, | ||
vol.Optional(CONF_CLIMATE, default={}): CLIMATE_SCHEMA, | ||
}), | ||
}, extra=vol.ALLOW_EXTRA) | ||
|
||
REQUIREMENTS = ['pyotgw==0.1b0'] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup(hass, config): | ||
"""Set up the OpenTherm Gateway component.""" | ||
import pyotgw | ||
conf = config[DOMAIN] | ||
gateway = pyotgw.pyotgw() | ||
hass.data[DATA_OPENTHERM_GW] = { | ||
DATA_DEVICE: gateway, | ||
DATA_GW_VARS: pyotgw.vars, | ||
} | ||
hass.async_create_task(connect_and_subscribe( | ||
hass, conf[CONF_DEVICE], gateway)) | ||
hass.async_create_task(async_load_platform( | ||
hass, 'climate', DOMAIN, conf.get(CONF_CLIMATE))) | ||
return True | ||
|
||
|
||
async def connect_and_subscribe(hass, device_path, gateway): | ||
"""Connect to serial device and subscribe report handler.""" | ||
await gateway.connect(hass.loop, device_path) | ||
_LOGGER.debug("Connected to OpenTherm Gateway at %s", device_path) | ||
|
||
async def handle_report(status): | ||
"""Handle reports from the OpenTherm Gateway.""" | ||
_LOGGER.debug("Received report: %s", status) | ||
async_dispatcher_send(hass, SIGNAL_OPENTHERM_GW_UPDATE, status) | ||
gateway.subscribe(handle_report) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters