2015-02-25 23:27:17 -08:00
|
|
|
"""
|
|
|
|
Interfaces with Z-Wave sensors.
|
2015-10-20 21:27:40 +02:00
|
|
|
|
2015-11-09 13:12:18 +01:00
|
|
|
For more details about this platform, please refer to the documentation
|
2016-02-23 06:21:49 +01:00
|
|
|
at https://home-assistant.io/components/sensor.zwave/
|
2015-02-25 23:27:17 -08:00
|
|
|
"""
|
2017-01-02 18:55:56 +01:00
|
|
|
import logging
|
2016-01-27 07:37:41 +01:00
|
|
|
from homeassistant.components.sensor import DOMAIN
|
2016-04-17 23:46:51 +02:00
|
|
|
from homeassistant.components import zwave
|
2016-04-19 20:30:44 -07:00
|
|
|
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
2018-07-20 11:45:20 +03:00
|
|
|
from homeassistant.components.zwave import async_setup_platform # noqa pylint: disable=unused-import
|
2016-01-26 22:11:27 +01:00
|
|
|
|
2017-01-02 18:55:56 +01:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2015-10-28 22:08:04 +01:00
|
|
|
|
2017-03-14 16:55:33 -07:00
|
|
|
def get_device(node, values, **kwargs):
|
2017-05-02 18:18:47 +02:00
|
|
|
"""Create Z-Wave entity device."""
|
2016-02-23 06:21:49 +01:00
|
|
|
# Generic Device mappings
|
2016-09-30 17:43:18 +02:00
|
|
|
if node.has_command_class(zwave.const.COMMAND_CLASS_SENSOR_MULTILEVEL):
|
2017-03-14 16:55:33 -07:00
|
|
|
return ZWaveMultilevelSensor(values)
|
2017-02-23 23:06:28 +02:00
|
|
|
if node.has_command_class(zwave.const.COMMAND_CLASS_METER) and \
|
2017-03-14 16:55:33 -07:00
|
|
|
values.primary.type == zwave.const.TYPE_DECIMAL:
|
|
|
|
return ZWaveMultilevelSensor(values)
|
2017-02-23 23:06:28 +02:00
|
|
|
if node.has_command_class(zwave.const.COMMAND_CLASS_ALARM) or \
|
2016-09-30 17:43:18 +02:00
|
|
|
node.has_command_class(zwave.const.COMMAND_CLASS_SENSOR_ALARM):
|
2017-03-14 16:55:33 -07:00
|
|
|
return ZWaveAlarmSensor(values)
|
2017-02-23 23:06:28 +02:00
|
|
|
return None
|
2015-11-15 17:50:11 +01:00
|
|
|
|
2015-03-01 01:35:58 -08:00
|
|
|
|
2017-01-27 01:21:33 -05:00
|
|
|
class ZWaveSensor(zwave.ZWaveDeviceEntity):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Representation of a Z-Wave sensor."""
|
2015-10-28 22:08:04 +01:00
|
|
|
|
2017-03-14 16:55:33 -07:00
|
|
|
def __init__(self, values):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Initialize the sensor."""
|
2017-03-14 16:55:33 -07:00
|
|
|
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
|
2017-02-18 08:56:05 +01:00
|
|
|
self.update_properties()
|
|
|
|
|
|
|
|
def update_properties(self):
|
2017-05-02 18:18:47 +02:00
|
|
|
"""Handle the data changes for node values."""
|
2017-03-14 16:55:33 -07:00
|
|
|
self._state = self.values.primary.data
|
|
|
|
self._units = self.values.primary.units
|
2015-02-28 22:49:55 -08:00
|
|
|
|
2017-02-13 00:10:56 +02:00
|
|
|
@property
|
|
|
|
def force_update(self):
|
|
|
|
"""Return force_update."""
|
|
|
|
return True
|
|
|
|
|
2015-02-22 17:36:28 -08:00
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Return the state of the sensor."""
|
2017-02-18 08:56:05 +01:00
|
|
|
return self._state
|
2015-02-22 17:36:28 -08:00
|
|
|
|
|
|
|
@property
|
2015-03-18 23:02:58 -07:00
|
|
|
def unit_of_measurement(self):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Return the unit of measurement the value is expressed in."""
|
2017-02-18 08:56:05 +01:00
|
|
|
return self._units
|
2015-02-25 23:27:17 -08:00
|
|
|
|
2015-02-22 17:36:28 -08:00
|
|
|
|
2015-02-25 23:27:17 -08:00
|
|
|
class ZWaveMultilevelSensor(ZWaveSensor):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Representation of a multi level sensor Z-Wave sensor."""
|
|
|
|
|
2015-02-22 17:36:28 -08:00
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Return the state of the sensor."""
|
2017-02-18 08:56:05 +01:00
|
|
|
if self._units in ('C', 'F'):
|
|
|
|
return round(self._state, 1)
|
2018-07-23 11:16:05 +03:00
|
|
|
if isinstance(self._state, float):
|
2017-02-18 08:56:05 +01:00
|
|
|
return round(self._state, 2)
|
2015-02-25 23:27:17 -08:00
|
|
|
|
2017-02-18 08:56:05 +01:00
|
|
|
return self._state
|
2015-02-22 17:36:28 -08:00
|
|
|
|
|
|
|
@property
|
2015-03-18 23:02:58 -07:00
|
|
|
def unit_of_measurement(self):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Return the unit the value is expressed in."""
|
2017-02-18 08:56:05 +01:00
|
|
|
if self._units == 'C':
|
2016-04-19 20:30:44 -07:00
|
|
|
return TEMP_CELSIUS
|
2018-07-23 11:16:05 +03:00
|
|
|
if self._units == 'F':
|
2015-02-22 17:36:28 -08:00
|
|
|
return TEMP_FAHRENHEIT
|
2017-07-05 23:30:01 -07:00
|
|
|
return self._units
|
2016-01-11 20:46:45 -08:00
|
|
|
|
2016-01-11 23:27:53 -08:00
|
|
|
|
2016-01-11 20:46:45 -08:00
|
|
|
class ZWaveAlarmSensor(ZWaveSensor):
|
2016-03-08 16:46:34 +01:00
|
|
|
"""Representation of a Z-Wave sensor that sends Alarm alerts.
|
2016-01-11 23:27:53 -08:00
|
|
|
|
2016-02-23 06:21:49 +01:00
|
|
|
Examples include certain Multisensors that have motion and vibration
|
|
|
|
capabilities. Z-Wave defines various alarm types such as Smoke, Flood,
|
|
|
|
Burglar, CarbonMonoxide, etc.
|
2016-01-11 23:27:53 -08:00
|
|
|
|
2016-02-23 06:21:49 +01:00
|
|
|
This wraps these alarms and allows you to use them to trigger things, etc.
|
2016-01-11 23:27:53 -08:00
|
|
|
|
|
|
|
COMMAND_CLASS_ALARM is what we get here.
|
2016-01-11 20:46:45 -08:00
|
|
|
"""
|
2016-03-08 16:46:34 +01:00
|
|
|
|
2016-01-11 23:27:53 -08:00
|
|
|
pass
|