Restore unit_of_measurement from entity registry (#30780)

* Restore unit_of_measurement from entity registry

* Lint fix
This commit is contained in:
Jc2k authored and Franck Nijhof committed 2020-01-15 20:17:42 +01:00
1 parent 3fd14ca3cf
commit 1a6535ff8b
5 files changed
+55

No files matched your search

+5
View File
@@ -922,6 +922,11 @@ class MockEntity(entity.Entity):
"""Info how device should be classified."""
return self._handle("device_class")
@property
def unit_of_measurement(self):
"""Info on the units the entity state is in."""
return self._handle("unit_of_measurement")
@property
def capability_attributes(self):
"""Info about capabilities."""
@@ -1,4 +1,5 @@
"""Test different accessory types: Sensors."""
from homeassistant.components.homekit import get_accessory
from homeassistant.components.homekit.const import (
PROP_CELSIUS,
THRESHOLD_CO,
@@ -17,6 +18,7 @@ from homeassistant.components.homekit.type_sensors import (
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_UNIT_OF_MEASUREMENT,
EVENT_HOMEASSISTANT_START,
STATE_HOME,
STATE_NOT_HOME,
STATE_OFF,
@@ -25,6 +27,8 @@ from homeassistant.const import (
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
)
from homeassistant.core import CoreState
from homeassistant.helpers import entity_registry
async def test_temperature(hass, hk_driver):
@@ -262,3 +266,34 @@ async def test_binary_device_classes(hass, hk_driver):
acc = BinarySensor(hass, hk_driver, "Binary Sensor", entity_id, 2, None)
assert acc.get_service(service).display_name == service
assert acc.char_detected.display_name == char
async def test_sensor_restore(hass, hk_driver, events):
"""Test setting up an entity from state in the event registry."""
hass.state = CoreState.not_running
registry = await entity_registry.async_get_registry(hass)
registry.async_get_or_create(
"sensor",
"generic",
"1234",
suggested_object_id="temperature",
device_class="temperature",
)
registry.async_get_or_create(
"sensor",
"generic",
"12345",
suggested_object_id="humidity",
device_class="humidity",
unit_of_measurement="%",
)
hass.bus.async_fire(EVENT_HOMEASSISTANT_START, {})
await hass.async_block_till_done()
acc = get_accessory(hass, hk_driver, hass.states.get("sensor.temperature"), 2, {})
assert acc.category == 10
acc = get_accessory(hass, hk_driver, hass.states.get("sensor.humidity"), 2, {})
assert acc.category == 10
+2
View File
@@ -804,6 +804,7 @@ async def test_entity_info_added_to_entity_registry(hass):
capability_attributes={"max": 100},
supported_features=5,
device_class="mock-device-class",
unit_of_measurement="%",
)
await component.async_add_entities([entity_default])
@@ -815,6 +816,7 @@ async def test_entity_info_added_to_entity_registry(hass):
assert entry_default.capabilities == {"max": 100}
assert entry_default.supported_features == 5
assert entry_default.device_class == "mock-device-class"
assert entry_default.unit_of_measurement == "%"
async def test_override_restored_entities(hass):