Add missing device class attributes to homekit_controller sensors (#32175)

* Add some missing device class attributes to homekit_controller sensors

* Add classes for binary sensors
This commit is contained in:
Jc2k 2020-02-25 20:43:14 +00:00 committed by GitHub
parent 24652d82ab
commit dd13e99967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 52 additions and 2 deletions

View File

@ -4,6 +4,8 @@ import logging
from aiohomekit.model.characteristics import CharacteristicsTypes
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_SMOKE,
BinarySensorDevice,
)
@ -32,7 +34,7 @@ class HomeKitMotionSensor(HomeKitEntity, BinarySensorDevice):
@property
def device_class(self):
"""Define this binary_sensor as a motion sensor."""
return "motion"
return DEVICE_CLASS_MOTION
@property
def is_on(self):
@ -55,6 +57,11 @@ class HomeKitContactSensor(HomeKitEntity, BinarySensorDevice):
def _update_contact_state(self, value):
self._state = value
@property
def device_class(self):
"""Define this binary_sensor as a opening sensor."""
return DEVICE_CLASS_OPENING
@property
def is_on(self):
"""Return true if the binary sensor is on/open."""

View File

@ -4,6 +4,9 @@ from aiohomekit.model.characteristics import CharacteristicsTypes
from homeassistant.const import (
CONCENTRATION_PARTS_PER_MILLION,
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TEMPERATURE,
TEMP_CELSIUS,
)
from homeassistant.core import callback
@ -31,6 +34,11 @@ class HomeKitHumiditySensor(HomeKitEntity):
"""Define the homekit characteristics the entity is tracking."""
return [CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT]
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_HUMIDITY
@property
def name(self):
"""Return the name of the device."""
@ -67,6 +75,11 @@ class HomeKitTemperatureSensor(HomeKitEntity):
"""Define the homekit characteristics the entity is tracking."""
return [CharacteristicsTypes.TEMPERATURE_CURRENT]
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_TEMPERATURE
@property
def name(self):
"""Return the name of the device."""
@ -103,6 +116,11 @@ class HomeKitLightSensor(HomeKitEntity):
"""Define the homekit characteristics the entity is tracking."""
return [CharacteristicsTypes.LIGHT_LEVEL_CURRENT]
@property
def device_class(self) -> str:
"""Return the device class of the sensor."""
return DEVICE_CLASS_ILLUMINANCE
@property
def name(self):
"""Return the name of the device."""

View File

@ -2,6 +2,12 @@
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_SMOKE,
)
from tests.components.homekit_controller.common import setup_test_component
MOTION_DETECTED = ("motion", "motion-detected")
@ -29,6 +35,8 @@ async def test_motion_sensor_read_state(hass, utcnow):
state = await helper.poll_and_get_state()
assert state.state == "on"
assert state.attributes["device_class"] == DEVICE_CLASS_MOTION
def create_contact_sensor_service(accessory):
"""Define contact characteristics."""
@ -50,6 +58,8 @@ async def test_contact_sensor_read_state(hass, utcnow):
state = await helper.poll_and_get_state()
assert state.state == "on"
assert state.attributes["device_class"] == DEVICE_CLASS_OPENING
def create_smoke_sensor_service(accessory):
"""Define smoke sensor characteristics."""
@ -71,4 +81,4 @@ async def test_smoke_sensor_read_state(hass, utcnow):
state = await helper.poll_and_get_state()
assert state.state == "on"
assert state.attributes["device_class"] == "smoke"
assert state.attributes["device_class"] == DEVICE_CLASS_SMOKE

View File

@ -2,6 +2,13 @@
from aiohomekit.model.characteristics import CharacteristicsTypes
from aiohomekit.model.services import ServicesTypes
from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TEMPERATURE,
)
from tests.components.homekit_controller.common import setup_test_component
TEMPERATURE = ("temperature", "temperature.current")
@ -75,6 +82,8 @@ async def test_temperature_sensor_read_state(hass, utcnow):
state = await helper.poll_and_get_state()
assert state.state == "20"
assert state.attributes["device_class"] == DEVICE_CLASS_TEMPERATURE
async def test_humidity_sensor_read_state(hass, utcnow):
"""Test reading the state of a HomeKit humidity sensor accessory."""
@ -90,6 +99,8 @@ async def test_humidity_sensor_read_state(hass, utcnow):
state = await helper.poll_and_get_state()
assert state.state == "20"
assert state.attributes["device_class"] == DEVICE_CLASS_HUMIDITY
async def test_light_level_sensor_read_state(hass, utcnow):
"""Test reading the state of a HomeKit temperature sensor accessory."""
@ -105,6 +116,8 @@ async def test_light_level_sensor_read_state(hass, utcnow):
state = await helper.poll_and_get_state()
assert state.state == "20"
assert state.attributes["device_class"] == DEVICE_CLASS_ILLUMINANCE
async def test_carbon_dioxide_level_sensor_read_state(hass, utcnow):
"""Test reading the state of a HomeKit carbon dioxide sensor accessory."""
@ -137,6 +150,8 @@ async def test_battery_level_sensor(hass, utcnow):
assert state.state == "20"
assert state.attributes["icon"] == "mdi:battery-20"
assert state.attributes["device_class"] == DEVICE_CLASS_BATTERY
async def test_battery_charging(hass, utcnow):
"""Test reading the state of a HomeKit battery's charging state."""