Refactor zwave discovery to entity schema (#6445)

* Refactor zwave discovery to entity schema

* Address PR concerns

* Split DISCOVERY_SCHEMAS into separate file

* Only check cover reverse workaround once
This commit is contained in:
Adam Mills 2017-03-13 02:13:34 -04:00 committed by Paulus Schoutsen
parent 55d60a6a13
commit 56abc7f9b4
11 changed files with 658 additions and 565 deletions

View file

@ -15,34 +15,34 @@ from homeassistant.components.zwave import async_setup_platform # noqa # pylint
_LOGGER = logging.getLogger(__name__)
def get_device(node, value, **kwargs):
def get_device(node, values, **kwargs):
"""Create zwave entity device."""
# Generic Device mappings
if value.command_class == zwave.const.COMMAND_CLASS_BATTERY:
return ZWaveSensor(value)
if values.primary.command_class == zwave.const.COMMAND_CLASS_BATTERY:
return ZWaveSensor(values)
if node.has_command_class(zwave.const.COMMAND_CLASS_SENSOR_MULTILEVEL):
return ZWaveMultilevelSensor(value)
return ZWaveMultilevelSensor(values)
if node.has_command_class(zwave.const.COMMAND_CLASS_METER) and \
value.type == zwave.const.TYPE_DECIMAL:
return ZWaveMultilevelSensor(value)
values.primary.type == zwave.const.TYPE_DECIMAL:
return ZWaveMultilevelSensor(values)
if node.has_command_class(zwave.const.COMMAND_CLASS_ALARM) or \
node.has_command_class(zwave.const.COMMAND_CLASS_SENSOR_ALARM):
return ZWaveAlarmSensor(value)
return ZWaveAlarmSensor(values)
return None
class ZWaveSensor(zwave.ZWaveDeviceEntity):
"""Representation of a Z-Wave sensor."""
def __init__(self, value):
def __init__(self, values):
"""Initialize the sensor."""
zwave.ZWaveDeviceEntity.__init__(self, value, DOMAIN)
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
self.update_properties()
def update_properties(self):
"""Callback on data changes for node values."""
self._state = self._value.data
self._units = self._value.units
self._state = self.values.primary.data
self._units = self.values.primary.units
@property
def force_update(self):