Migrate ISY994 to PyISY v2 (#35338)
* Remove unnecessary pylint exceptions
* Move up some change to binary_sensors and switch. Fix program d.s.a's.
* ISY994 Basic support for PyISYv2
- Bare minimum changes to be able to support PyISYv2.
- Renaming imports and functions to new names.
- Use necessary constants from module.
- **BREAKING CHANGE** Remove ISY Climate Module support.
- Climate module was retired on 3/30/2020: [UDI Annoucement](https://www.universal-devices.com/byebyeclimatemodule/)
- **BREAKING CHANGE** Device State Attributes use NodeProperty
- Some attributes names and types will have changed as part of the changes to PyISY. If a user relied on a device state attribute for a given entity, they should check that it is still there and formatted the same. In general, *more* state attributes should be getting picked up now that the underlying changes have been made.
- **BREAKING CHANGE** `isy994_control` event changes (using NodeProperty)
- Control events now return an object with additional information. Control events are now parsed to the friendly names and will need to be updated in automations.
Remove cast
* PyISY v2.0.2, add extra UOMs, omit EMPTY_TIME attributes
* Fix typo in function doc string.
Co-authored-by: J. Nick Koston <nick@koston.org>
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
1 parent
7ac547a6e0
commit
4ec88b41dc
13 files changed
+268
-245
No files matched your search
@@ -1,13 +1,15 @@
|
||||
"""Support for ISY994 sensors."""
|
||||
from typing import Callable
|
||||
|
||||
from pyisy.constants import ISY_VALUE_UNKNOWN
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN as SENSOR
|
||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.const import STATE_UNKNOWN, TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import ISY994_NODES, ISY994_WEATHER
|
||||
from . import ISY994_NODES
|
||||
from .const import _LOGGER, UOM_FRIENDLY_NAME, UOM_TO_STATES
|
||||
from .entity import ISYEntity, ISYNodeEntity
|
||||
from .entity import ISYNodeEntity
|
||||
|
||||
|
||||
def setup_platform(
|
||||
@@ -20,9 +22,6 @@ def setup_platform(
|
||||
_LOGGER.debug("Loading %s", node.name)
|
||||
devices.append(ISYSensorEntity(node))
|
||||
|
||||
for node in hass.data[ISY994_WEATHER]:
|
||||
devices.append(ISYWeatherDevice(node))
|
||||
|
||||
add_entities(devices)
|
||||
|
||||
|
||||
@@ -32,42 +31,40 @@ class ISYSensorEntity(ISYNodeEntity):
|
||||
@property
|
||||
def raw_unit_of_measurement(self) -> str:
|
||||
"""Get the raw unit of measurement for the ISY994 sensor device."""
|
||||
if len(self._node.uom) == 1:
|
||||
if self._node.uom[0] in UOM_FRIENDLY_NAME:
|
||||
friendly_name = UOM_FRIENDLY_NAME.get(self._node.uom[0])
|
||||
if friendly_name in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
||||
friendly_name = self.hass.config.units.temperature_unit
|
||||
return friendly_name
|
||||
return self._node.uom[0]
|
||||
return None
|
||||
uom = self._node.uom
|
||||
|
||||
# Backwards compatibility for ISYv4 Firmware:
|
||||
if isinstance(uom, list):
|
||||
return UOM_FRIENDLY_NAME.get(uom[0], uom[0])
|
||||
return UOM_FRIENDLY_NAME.get(uom)
|
||||
|
||||
@property
|
||||
def state(self) -> str:
|
||||
"""Get the state of the ISY994 sensor device."""
|
||||
if self.is_unknown():
|
||||
return None
|
||||
if self.value == ISY_VALUE_UNKNOWN:
|
||||
return STATE_UNKNOWN
|
||||
|
||||
if len(self._node.uom) == 1:
|
||||
if self._node.uom[0] in UOM_TO_STATES:
|
||||
states = UOM_TO_STATES.get(self._node.uom[0])
|
||||
# TEMPORARY: Cast value to int until PyISYv2.
|
||||
if int(self.value) in states:
|
||||
return states.get(int(self.value))
|
||||
elif self._node.prec and self._node.prec != [0]:
|
||||
str_val = str(self.value)
|
||||
int_prec = int(self._node.prec)
|
||||
decimal_part = str_val[-int_prec:]
|
||||
whole_part = str_val[: len(str_val) - int_prec]
|
||||
val = float(f"{whole_part}.{decimal_part}")
|
||||
raw_units = self.raw_unit_of_measurement
|
||||
if raw_units in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
||||
val = self.hass.config.units.temperature(val, raw_units)
|
||||
uom = self._node.uom
|
||||
# Backwards compatibility for ISYv4 Firmware:
|
||||
if isinstance(uom, list):
|
||||
uom = uom[0]
|
||||
if not uom:
|
||||
return STATE_UNKNOWN
|
||||
|
||||
return str(val)
|
||||
else:
|
||||
return self.value
|
||||
|
||||
return None
|
||||
states = UOM_TO_STATES.get(uom)
|
||||
if states and states.get(self.value):
|
||||
return states.get(self.value)
|
||||
if self._node.prec and int(self._node.prec) != 0:
|
||||
str_val = str(self.value)
|
||||
int_prec = int(self._node.prec)
|
||||
decimal_part = str_val[-int_prec:]
|
||||
whole_part = str_val[: len(str_val) - int_prec]
|
||||
val = float(f"{whole_part}.{decimal_part}")
|
||||
raw_units = self.raw_unit_of_measurement
|
||||
if raw_units in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
||||
val = self.hass.config.units.temperature(val, raw_units)
|
||||
return val
|
||||
return self.value
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self) -> str:
|
||||
@@ -76,37 +73,3 @@ class ISYSensorEntity(ISYNodeEntity):
|
||||
if raw_units in (TEMP_FAHRENHEIT, TEMP_CELSIUS):
|
||||
return self.hass.config.units.temperature_unit
|
||||
return raw_units
|
||||
|
||||
|
||||
# Depreciated, not renaming. Will be removed in next PR.
|
||||
class ISYWeatherDevice(ISYEntity):
|
||||
"""Representation of an ISY994 weather device."""
|
||||
|
||||
@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
|
||||
Reference in new issue
Block a user