diff --git a/homeassistant/components/isy994.py b/homeassistant/components/isy994.py index 0539469f198..7451b3286f7 100644 --- a/homeassistant/components/isy994.py +++ b/homeassistant/components/isy994.py @@ -4,6 +4,7 @@ Support the ISY-994 controllers. For configuration details please visit the documentation for this component at https://home-assistant.io/components/isy994/ """ +from collections import namedtuple import logging from urllib.parse import urlparse import voluptuous as vol @@ -47,6 +48,7 @@ CONFIG_SCHEMA = vol.Schema({ }, extra=vol.ALLOW_EXTRA) SENSOR_NODES = [] +WEATHER_NODES = [] NODES = [] GROUPS = [] PROGRAMS = {} @@ -59,6 +61,9 @@ SUPPORTED_DOMAINS = ['binary_sensor', 'cover', 'fan', 'light', 'lock', 'sensor', 'switch'] +WeatherNode = namedtuple('WeatherNode', ('status', 'name', 'uom')) + + def filter_nodes(nodes: list, units: list=None, states: list=None) -> list: """Filter a list of ISY nodes based on the units and states provided.""" filtered_nodes = [] @@ -132,6 +137,17 @@ def _categorize_programs() -> None: PROGRAMS[component].append(program) +def _categorize_weather() -> None: + """Categorize the ISY994 weather data.""" + global WEATHER_NODES + + climate_attrs = dir(ISY.climate) + WEATHER_NODES = [WeatherNode(getattr(ISY.climate, attr), attr, + getattr(ISY.climate, attr + '_units')) + for attr in climate_attrs + if attr + '_units' in climate_attrs] + + def setup(hass: HomeAssistant, config: ConfigType) -> bool: """Set up the ISY 994 platform.""" isy_config = config.get(DOMAIN) @@ -178,6 +194,9 @@ def setup(hass: HomeAssistant, config: ConfigType) -> bool: _categorize_programs() + if ISY.configuration.get('Weather Information'): + _categorize_weather() + # Listen for HA stop to disconnect. hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop) diff --git a/homeassistant/components/sensor/isy994.py b/homeassistant/components/sensor/isy994.py index df3ae9ed7ba..d35c76b81dc 100644 --- a/homeassistant/components/sensor/isy994.py +++ b/homeassistant/components/sensor/isy994.py @@ -251,6 +251,9 @@ def setup_platform(hass, config: ConfigType, _LOGGER.debug('LOADING %s', node.name) devices.append(ISYSensorDevice(node)) + for node in isy.WEATHER_NODES: + devices.append(ISYWeatherDevice(node)) + add_devices(devices) @@ -309,3 +312,47 @@ class ISYSensorDevice(isy.ISYDevice): return self.hass.config.units.temperature_unit else: return raw_units + + +class ISYWeatherDevice(isy.ISYDevice): + """Representation of an ISY994 weather device.""" + + _domain = 'sensor' + + def __init__(self, node) -> None: + """Initialize the ISY994 weather device.""" + isy.ISYDevice.__init__(self, node) + + @property + def unique_id(self) -> str: + """Return the unique identifier for the node.""" + return self._node.name + + @property + def raw_units(self) -> str: + """Return the raw unit of measurement.""" + if self._node.uom == 'F': + return TEMP_FAHRENHEIT + if self._node.uom == 'C': + return TEMP_CELSIUS + return self._node.uom + + @property + def state(self) -> object: + """Return the value of the node.""" + # pylint: disable=protected-access + val = self._node.status._val + raw_units = self._node.uom + + if raw_units in [TEMP_CELSIUS, TEMP_FAHRENHEIT]: + return self.hass.config.units.temperature(val, raw_units) + return val + + @property + def unit_of_measurement(self) -> str: + """Return the unit of measurement for the node.""" + raw_units = self.raw_units + + if raw_units in [TEMP_CELSIUS, TEMP_FAHRENHEIT]: + return self.hass.config.units.temperature_unit + return raw_units