Change deCONZ sensor device classes (#36352)
* Change vibration type to vibration instead of motion * Also replace icon and unit of measurement
This commit is contained in:
parent
bde94d187c
commit
37f7d262d7
4 changed files with 73 additions and 11 deletions
|
@ -1,7 +1,15 @@
|
||||||
"""Support for deCONZ binary sensors."""
|
"""Support for deCONZ binary sensors."""
|
||||||
from pydeconz.sensor import Presence, Vibration
|
from pydeconz.sensor import CarbonMonoxide, Fire, OpenClose, Presence, Vibration, Water
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
from homeassistant.components.binary_sensor import (
|
||||||
|
DEVICE_CLASS_GAS,
|
||||||
|
DEVICE_CLASS_MOISTURE,
|
||||||
|
DEVICE_CLASS_MOTION,
|
||||||
|
DEVICE_CLASS_OPENING,
|
||||||
|
DEVICE_CLASS_SMOKE,
|
||||||
|
DEVICE_CLASS_VIBRATION,
|
||||||
|
BinarySensorEntity,
|
||||||
|
)
|
||||||
from homeassistant.const import ATTR_TEMPERATURE
|
from homeassistant.const import ATTR_TEMPERATURE
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
@ -14,6 +22,15 @@ ATTR_ORIENTATION = "orientation"
|
||||||
ATTR_TILTANGLE = "tiltangle"
|
ATTR_TILTANGLE = "tiltangle"
|
||||||
ATTR_VIBRATIONSTRENGTH = "vibrationstrength"
|
ATTR_VIBRATIONSTRENGTH = "vibrationstrength"
|
||||||
|
|
||||||
|
DEVICE_CLASS = {
|
||||||
|
CarbonMonoxide: DEVICE_CLASS_GAS,
|
||||||
|
Fire: DEVICE_CLASS_SMOKE,
|
||||||
|
OpenClose: DEVICE_CLASS_OPENING,
|
||||||
|
Presence: DEVICE_CLASS_MOTION,
|
||||||
|
Vibration: DEVICE_CLASS_VIBRATION,
|
||||||
|
Water: DEVICE_CLASS_MOISTURE,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Old way of setting up deCONZ platforms."""
|
"""Old way of setting up deCONZ platforms."""
|
||||||
|
@ -74,12 +91,7 @@ class DeconzBinarySensor(DeconzDevice, BinarySensorEntity):
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the class of the sensor."""
|
"""Return the class of the sensor."""
|
||||||
return self._device.SENSOR_CLASS
|
return DEVICE_CLASS.get(type(self._device))
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon to use in the frontend."""
|
|
||||||
return self._device.SENSOR_ICON
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
|
|
|
@ -3,9 +3,12 @@ from pydeconz.sensor import (
|
||||||
Battery,
|
Battery,
|
||||||
Consumption,
|
Consumption,
|
||||||
Daylight,
|
Daylight,
|
||||||
|
Humidity,
|
||||||
LightLevel,
|
LightLevel,
|
||||||
Power,
|
Power,
|
||||||
|
Pressure,
|
||||||
Switch,
|
Switch,
|
||||||
|
Temperature,
|
||||||
Thermostat,
|
Thermostat,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -13,6 +16,15 @@ from homeassistant.const import (
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
ATTR_VOLTAGE,
|
ATTR_VOLTAGE,
|
||||||
DEVICE_CLASS_BATTERY,
|
DEVICE_CLASS_BATTERY,
|
||||||
|
DEVICE_CLASS_HUMIDITY,
|
||||||
|
DEVICE_CLASS_ILLUMINANCE,
|
||||||
|
DEVICE_CLASS_POWER,
|
||||||
|
DEVICE_CLASS_PRESSURE,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
ENERGY_KILO_WATT_HOUR,
|
||||||
|
POWER_WATT,
|
||||||
|
PRESSURE_HPA,
|
||||||
|
TEMP_CELSIUS,
|
||||||
UNIT_PERCENTAGE,
|
UNIT_PERCENTAGE,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
@ -31,6 +43,29 @@ ATTR_POWER = "power"
|
||||||
ATTR_DAYLIGHT = "daylight"
|
ATTR_DAYLIGHT = "daylight"
|
||||||
ATTR_EVENT_ID = "event_id"
|
ATTR_EVENT_ID = "event_id"
|
||||||
|
|
||||||
|
DEVICE_CLASS = {
|
||||||
|
Humidity: DEVICE_CLASS_HUMIDITY,
|
||||||
|
LightLevel: DEVICE_CLASS_ILLUMINANCE,
|
||||||
|
Power: DEVICE_CLASS_POWER,
|
||||||
|
Pressure: DEVICE_CLASS_PRESSURE,
|
||||||
|
Temperature: DEVICE_CLASS_TEMPERATURE,
|
||||||
|
}
|
||||||
|
|
||||||
|
ICON = {
|
||||||
|
Daylight: "mdi:white-balance-sunny",
|
||||||
|
Pressure: "mdi:gauge",
|
||||||
|
Temperature: "mdi:thermometer",
|
||||||
|
}
|
||||||
|
|
||||||
|
UNIT_OF_MEASUREMENT = {
|
||||||
|
Consumption: ENERGY_KILO_WATT_HOUR,
|
||||||
|
Humidity: UNIT_PERCENTAGE,
|
||||||
|
LightLevel: "lx",
|
||||||
|
Power: POWER_WATT,
|
||||||
|
Pressure: PRESSURE_HPA,
|
||||||
|
Temperature: TEMP_CELSIUS,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||||
"""Old way of setting up deCONZ platforms."""
|
"""Old way of setting up deCONZ platforms."""
|
||||||
|
@ -119,17 +154,17 @@ class DeconzSensor(DeconzDevice):
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the class of the sensor."""
|
"""Return the class of the sensor."""
|
||||||
return self._device.SENSOR_CLASS
|
return DEVICE_CLASS.get(type(self._device))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
"""Return the icon to use in the frontend."""
|
"""Return the icon to use in the frontend."""
|
||||||
return self._device.SENSOR_ICON
|
return ICON.get(type(self._device))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement of this sensor."""
|
"""Return the unit of measurement of this sensor."""
|
||||||
return self._device.SENSOR_UNIT
|
return UNIT_OF_MEASUREMENT.get(type(self._device))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
|
|
|
@ -3,6 +3,10 @@ from copy import deepcopy
|
||||||
|
|
||||||
from homeassistant.components import deconz
|
from homeassistant.components import deconz
|
||||||
import homeassistant.components.binary_sensor as binary_sensor
|
import homeassistant.components.binary_sensor as binary_sensor
|
||||||
|
from homeassistant.components.binary_sensor import (
|
||||||
|
DEVICE_CLASS_MOTION,
|
||||||
|
DEVICE_CLASS_VIBRATION,
|
||||||
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||||
|
@ -79,6 +83,7 @@ async def test_binary_sensors(hass):
|
||||||
|
|
||||||
presence_sensor = hass.states.get("binary_sensor.presence_sensor")
|
presence_sensor = hass.states.get("binary_sensor.presence_sensor")
|
||||||
assert presence_sensor.state == "off"
|
assert presence_sensor.state == "off"
|
||||||
|
assert presence_sensor.attributes["device_class"] == DEVICE_CLASS_MOTION
|
||||||
|
|
||||||
temperature_sensor = hass.states.get("binary_sensor.temperature_sensor")
|
temperature_sensor = hass.states.get("binary_sensor.temperature_sensor")
|
||||||
assert temperature_sensor is None
|
assert temperature_sensor is None
|
||||||
|
@ -88,6 +93,7 @@ async def test_binary_sensors(hass):
|
||||||
|
|
||||||
vibration_sensor = hass.states.get("binary_sensor.vibration_sensor")
|
vibration_sensor = hass.states.get("binary_sensor.vibration_sensor")
|
||||||
assert vibration_sensor.state == "on"
|
assert vibration_sensor.state == "on"
|
||||||
|
assert vibration_sensor.attributes["device_class"] == DEVICE_CLASS_VIBRATION
|
||||||
|
|
||||||
state_changed_event = {
|
state_changed_event = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
|
|
|
@ -3,6 +3,11 @@ from copy import deepcopy
|
||||||
|
|
||||||
from homeassistant.components import deconz
|
from homeassistant.components import deconz
|
||||||
import homeassistant.components.sensor as sensor
|
import homeassistant.components.sensor as sensor
|
||||||
|
from homeassistant.const import (
|
||||||
|
DEVICE_CLASS_BATTERY,
|
||||||
|
DEVICE_CLASS_ILLUMINANCE,
|
||||||
|
DEVICE_CLASS_POWER,
|
||||||
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
from .test_gateway import DECONZ_WEB_REQUEST, setup_deconz_integration
|
||||||
|
@ -112,6 +117,7 @@ async def test_sensors(hass):
|
||||||
|
|
||||||
light_level_sensor = hass.states.get("sensor.light_level_sensor")
|
light_level_sensor = hass.states.get("sensor.light_level_sensor")
|
||||||
assert light_level_sensor.state == "999.8"
|
assert light_level_sensor.state == "999.8"
|
||||||
|
assert light_level_sensor.attributes["device_class"] == DEVICE_CLASS_ILLUMINANCE
|
||||||
|
|
||||||
presence_sensor = hass.states.get("sensor.presence_sensor")
|
presence_sensor = hass.states.get("sensor.presence_sensor")
|
||||||
assert presence_sensor is None
|
assert presence_sensor is None
|
||||||
|
@ -127,15 +133,18 @@ async def test_sensors(hass):
|
||||||
|
|
||||||
switch_2_battery_level = hass.states.get("sensor.switch_2_battery_level")
|
switch_2_battery_level = hass.states.get("sensor.switch_2_battery_level")
|
||||||
assert switch_2_battery_level.state == "100"
|
assert switch_2_battery_level.state == "100"
|
||||||
|
assert switch_2_battery_level.attributes["device_class"] == DEVICE_CLASS_BATTERY
|
||||||
|
|
||||||
daylight_sensor = hass.states.get("sensor.daylight_sensor")
|
daylight_sensor = hass.states.get("sensor.daylight_sensor")
|
||||||
assert daylight_sensor is None
|
assert daylight_sensor is None
|
||||||
|
|
||||||
power_sensor = hass.states.get("sensor.power_sensor")
|
power_sensor = hass.states.get("sensor.power_sensor")
|
||||||
assert power_sensor.state == "6"
|
assert power_sensor.state == "6"
|
||||||
|
assert power_sensor.attributes["device_class"] == DEVICE_CLASS_POWER
|
||||||
|
|
||||||
consumption_sensor = hass.states.get("sensor.consumption_sensor")
|
consumption_sensor = hass.states.get("sensor.consumption_sensor")
|
||||||
assert consumption_sensor.state == "0.002"
|
assert consumption_sensor.state == "0.002"
|
||||||
|
assert "device_class" not in consumption_sensor.attributes
|
||||||
|
|
||||||
state_changed_event = {
|
state_changed_event = {
|
||||||
"t": "event",
|
"t": "event",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue