Axis - Add device class property to binary sensors (#36384)
* Add device class property to binary sensors * Update tests
This commit is contained in:
parent
db8d4053d6
commit
770b622a6e
2 changed files with 32 additions and 3 deletions
|
@ -2,9 +2,21 @@
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from axis.event_stream import CLASS_INPUT, CLASS_OUTPUT
|
from axis.event_stream import (
|
||||||
|
CLASS_INPUT,
|
||||||
|
CLASS_LIGHT,
|
||||||
|
CLASS_MOTION,
|
||||||
|
CLASS_OUTPUT,
|
||||||
|
CLASS_SOUND,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
from homeassistant.components.binary_sensor import (
|
||||||
|
DEVICE_CLASS_CONNECTIVITY,
|
||||||
|
DEVICE_CLASS_LIGHT,
|
||||||
|
DEVICE_CLASS_MOTION,
|
||||||
|
DEVICE_CLASS_SOUND,
|
||||||
|
BinarySensorEntity,
|
||||||
|
)
|
||||||
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
|
||||||
from homeassistant.helpers.event import async_track_point_in_utc_time
|
from homeassistant.helpers.event import async_track_point_in_utc_time
|
||||||
|
@ -13,6 +25,13 @@ from homeassistant.util.dt import utcnow
|
||||||
from .axis_base import AxisEventBase
|
from .axis_base import AxisEventBase
|
||||||
from .const import DOMAIN as AXIS_DOMAIN
|
from .const import DOMAIN as AXIS_DOMAIN
|
||||||
|
|
||||||
|
DEVICE_CLASS = {
|
||||||
|
CLASS_INPUT: DEVICE_CLASS_CONNECTIVITY,
|
||||||
|
CLASS_LIGHT: DEVICE_CLASS_LIGHT,
|
||||||
|
CLASS_MOTION: DEVICE_CLASS_MOTION,
|
||||||
|
CLASS_SOUND: DEVICE_CLASS_SOUND,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||||
"""Set up a Axis binary sensor."""
|
"""Set up a Axis binary sensor."""
|
||||||
|
@ -84,3 +103,8 @@ class AxisBinarySensor(AxisEventBase, BinarySensorEntity):
|
||||||
)
|
)
|
||||||
|
|
||||||
return super().name
|
return super().name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the class of the sensor."""
|
||||||
|
return DEVICE_CLASS.get(self.event.CLASS)
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
"""Axis binary sensor platform tests."""
|
"""Axis binary sensor platform tests."""
|
||||||
|
|
||||||
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
|
from homeassistant.components.axis.const import DOMAIN as AXIS_DOMAIN
|
||||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
from homeassistant.components.binary_sensor import (
|
||||||
|
DEVICE_CLASS_MOTION,
|
||||||
|
DOMAIN as BINARY_SENSOR_DOMAIN,
|
||||||
|
)
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from .test_device import NAME, setup_axis_integration
|
from .test_device import NAME, setup_axis_integration
|
||||||
|
@ -58,7 +61,9 @@ async def test_binary_sensors(hass):
|
||||||
pir = hass.states.get(f"binary_sensor.{NAME}_pir_0")
|
pir = hass.states.get(f"binary_sensor.{NAME}_pir_0")
|
||||||
assert pir.state == "off"
|
assert pir.state == "off"
|
||||||
assert pir.name == f"{NAME} PIR 0"
|
assert pir.name == f"{NAME} PIR 0"
|
||||||
|
assert pir.attributes["device_class"] == DEVICE_CLASS_MOTION
|
||||||
|
|
||||||
vmd4 = hass.states.get(f"binary_sensor.{NAME}_vmd4_camera1profile1")
|
vmd4 = hass.states.get(f"binary_sensor.{NAME}_vmd4_camera1profile1")
|
||||||
assert vmd4.state == "on"
|
assert vmd4.state == "on"
|
||||||
assert vmd4.name == f"{NAME} VMD4 Camera1Profile1"
|
assert vmd4.name == f"{NAME} VMD4 Camera1Profile1"
|
||||||
|
assert vmd4.attributes["device_class"] == DEVICE_CLASS_MOTION
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue