Use entity category in devolo Home Control (#59104)
* Use entity category * Add tests
This commit is contained in:
parent
d709fcdd30
commit
442d65e8da
4 changed files with 37 additions and 5 deletions
|
@ -15,6 +15,7 @@ from homeassistant.components.binary_sensor import (
|
|||
BinarySensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
@ -94,8 +95,12 @@ class DevoloBinaryDeviceEntity(DevoloDeviceEntity, BinarySensorEntity):
|
|||
|
||||
self._value = self._binary_sensor_property.state
|
||||
|
||||
if self._attr_device_class == DEVICE_CLASS_SAFETY:
|
||||
self._attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
|
||||
|
||||
if element_uid.startswith("devolo.WarningBinaryFI:"):
|
||||
self._attr_device_class = DEVICE_CLASS_PROBLEM
|
||||
self._attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
|
||||
self._attr_entity_registry_enabled_default = False
|
||||
|
||||
@property
|
||||
|
|
|
@ -16,7 +16,7 @@ from homeassistant.components.sensor import (
|
|||
SensorEntity,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC, PERCENTAGE
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
|
@ -132,6 +132,7 @@ class DevoloBatteryEntity(DevoloMultiLevelDeviceEntity):
|
|||
)
|
||||
|
||||
self._attr_device_class = DEVICE_CLASS_MAPPING.get("battery")
|
||||
self._attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC
|
||||
self._attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
self._value = device_instance.battery_level
|
||||
|
|
|
@ -57,6 +57,16 @@ class BinarySensorMock(DeviceMock):
|
|||
self.binary_sensor_property = {"Test": BinarySensorPropertyMock()}
|
||||
|
||||
|
||||
class BinarySensorMockOverload(DeviceMock):
|
||||
"""devolo Home Control disabled binary sensor device mock."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the mock."""
|
||||
super().__init__()
|
||||
self.binary_sensor_property = {"Overload": BinarySensorPropertyMock()}
|
||||
self.binary_sensor_property["Overload"].sensor_type = "overload"
|
||||
|
||||
|
||||
class RemoteControlMock(DeviceMock):
|
||||
"""devolo Home Control remote control device mock."""
|
||||
|
||||
|
@ -90,12 +100,15 @@ class HomeControlMock(HomeControl):
|
|||
|
||||
|
||||
class HomeControlMockBinarySensor(HomeControlMock):
|
||||
"""devolo Home Control gateway mock with binary sensor device."""
|
||||
"""devolo Home Control gateway mock with binary sensor devices."""
|
||||
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
"""Initialize the mock."""
|
||||
super().__init__()
|
||||
self.devices = {"Test": BinarySensorMock()}
|
||||
self.devices = {
|
||||
"Test": BinarySensorMock(),
|
||||
"Overload": BinarySensorMockOverload(),
|
||||
}
|
||||
self.publisher = Publisher(self.devices.keys())
|
||||
self.publisher.unregister = MagicMock()
|
||||
|
||||
|
|
|
@ -4,8 +4,14 @@ from unittest.mock import patch
|
|||
import pytest
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE
|
||||
from homeassistant.const import (
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry
|
||||
|
||||
from . import configure_integration
|
||||
from .mocks import (
|
||||
|
@ -33,6 +39,13 @@ async def test_binary_sensor(hass: HomeAssistant):
|
|||
assert state is not None
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
state = hass.states.get(f"{DOMAIN}.test_2")
|
||||
assert state is not None
|
||||
er = entity_registry.async_get(hass)
|
||||
assert (
|
||||
er.async_get(f"{DOMAIN}.test_2").entity_category == ENTITY_CATEGORY_DIAGNOSTIC
|
||||
)
|
||||
|
||||
# Emulate websocket message: sensor turned on
|
||||
test_gateway.publisher.dispatch("Test", ("Test", True))
|
||||
await hass.async_block_till_done()
|
||||
|
@ -111,4 +124,4 @@ async def test_remove_from_hass(hass: HomeAssistant):
|
|||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_all()) == 0
|
||||
test_gateway.publisher.unregister.assert_called_once()
|
||||
assert test_gateway.publisher.unregister.call_count == 2
|
||||
|
|
Loading…
Add table
Reference in a new issue