Add support for Z-Wave battery level (#26943)
* Add support for Z-Wave battery level * Improve coverage
This commit is contained in:
parent
b1a9fa47ca
commit
eeffd090a3
3 changed files with 30 additions and 1 deletions
|
@ -277,6 +277,7 @@ DISCOVERY_SCHEMAS = [
|
||||||
const.COMMAND_CLASS_ALARM,
|
const.COMMAND_CLASS_ALARM,
|
||||||
const.COMMAND_CLASS_SENSOR_ALARM,
|
const.COMMAND_CLASS_SENSOR_ALARM,
|
||||||
const.COMMAND_CLASS_INDICATOR,
|
const.COMMAND_CLASS_INDICATOR,
|
||||||
|
const.COMMAND_CLASS_BATTERY,
|
||||||
],
|
],
|
||||||
const.DISC_GENRE: const.GENRE_USER,
|
const.DISC_GENRE: const.GENRE_USER,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Support for Z-Wave sensors."""
|
"""Support for Z-Wave sensors."""
|
||||||
import logging
|
import logging
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.components.sensor import DOMAIN
|
from homeassistant.components.sensor import DOMAIN, DEVICE_CLASS_BATTERY
|
||||||
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
from homeassistant.const import TEMP_CELSIUS, TEMP_FAHRENHEIT
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from . import const, ZWaveDeviceEntity
|
from . import const, ZWaveDeviceEntity
|
||||||
|
@ -28,6 +28,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
def get_device(node, values, **kwargs):
|
def get_device(node, values, **kwargs):
|
||||||
"""Create Z-Wave entity device."""
|
"""Create Z-Wave entity device."""
|
||||||
# Generic Device mappings
|
# Generic Device mappings
|
||||||
|
if values.primary.command_class == const.COMMAND_CLASS_BATTERY:
|
||||||
|
return ZWaveBatterySensor(values)
|
||||||
if node.has_command_class(const.COMMAND_CLASS_SENSOR_MULTILEVEL):
|
if node.has_command_class(const.COMMAND_CLASS_SENSOR_MULTILEVEL):
|
||||||
return ZWaveMultilevelSensor(values)
|
return ZWaveMultilevelSensor(values)
|
||||||
if (
|
if (
|
||||||
|
@ -107,3 +109,12 @@ class ZWaveAlarmSensor(ZWaveSensor):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ZWaveBatterySensor(ZWaveSensor):
|
||||||
|
"""Representation of Z-Wave device battery level."""
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the class of this device."""
|
||||||
|
return DEVICE_CLASS_BATTERY
|
||||||
|
|
|
@ -53,6 +53,23 @@ def test_get_device_detects_multilevel_meter(mock_openzwave):
|
||||||
assert isinstance(device, sensor.ZWaveMultilevelSensor)
|
assert isinstance(device, sensor.ZWaveMultilevelSensor)
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_device_detects_battery_sensor(mock_openzwave):
|
||||||
|
"""Test get_device returns a Z-Wave battery sensor."""
|
||||||
|
|
||||||
|
node = MockNode(command_classes=[const.COMMAND_CLASS_BATTERY])
|
||||||
|
value = MockValue(
|
||||||
|
data=0,
|
||||||
|
node=node,
|
||||||
|
type=const.TYPE_DECIMAL,
|
||||||
|
command_class=const.COMMAND_CLASS_BATTERY,
|
||||||
|
)
|
||||||
|
values = MockEntityValues(primary=value)
|
||||||
|
|
||||||
|
device = sensor.get_device(node=node, values=values, node_config={})
|
||||||
|
assert isinstance(device, sensor.ZWaveBatterySensor)
|
||||||
|
assert device.device_class == homeassistant.const.DEVICE_CLASS_BATTERY
|
||||||
|
|
||||||
|
|
||||||
def test_multilevelsensor_value_changed_temp_fahrenheit(mock_openzwave):
|
def test_multilevelsensor_value_changed_temp_fahrenheit(mock_openzwave):
|
||||||
"""Test value changed for Z-Wave multilevel sensor for temperature."""
|
"""Test value changed for Z-Wave multilevel sensor for temperature."""
|
||||||
node = MockNode(
|
node = MockNode(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue