Fix watts unit for homekit_controller power sensors (#53877)

pull/53887/head
Jc2k 2021-08-02 18:47:11 +01:00 committed by GitHub
parent 80a8f35a42
commit d414b58769
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 3 deletions

View File

@ -12,6 +12,7 @@ from homeassistant.const import (
DEVICE_CLASS_TEMPERATURE,
LIGHT_LUX,
PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
)
from homeassistant.core import callback
@ -29,19 +30,19 @@ SIMPLE_SENSOR = {
"name": "Real Time Energy",
"device_class": DEVICE_CLASS_POWER,
"state_class": STATE_CLASS_MEASUREMENT,
"unit": "watts",
"unit": POWER_WATT,
},
CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY: {
"name": "Real Time Energy",
"device_class": DEVICE_CLASS_POWER,
"state_class": STATE_CLASS_MEASUREMENT,
"unit": "watts",
"unit": POWER_WATT,
},
CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY_2: {
"name": "Real Time Energy",
"device_class": DEVICE_CLASS_POWER,
"state_class": STATE_CLASS_MEASUREMENT,
"unit": "watts",
"unit": POWER_WATT,
},
CharacteristicsTypes.get_uuid(CharacteristicsTypes.TEMPERATURE_CURRENT): {
"name": "Current Temperature",

View File

@ -1,5 +1,6 @@
"""Make sure that existing Koogeek P1EU support isn't broken."""
from homeassistant.const import POWER_WATT
from homeassistant.helpers import device_registry as dr, entity_registry as er
from tests.components.homekit_controller.common import (
@ -48,6 +49,7 @@ async def test_koogeek_p1eu_setup(hass):
)
state = await helper.poll_and_get_state()
assert state.attributes["friendly_name"] == "Koogeek-P1-A00AA0 - Real Time Energy"
assert state.attributes["unit_of_measurement"] == POWER_WATT
# The sensor and switch should be part of the same device
assert entry.device_id == device.id

View File

@ -6,6 +6,7 @@ This Koogeek device has a custom power sensor that extra handling.
It should have 2 entities - the actual switch and a sensor for power usage.
"""
from homeassistant.const import POWER_WATT
from homeassistant.helpers import device_registry as dr, entity_registry as er
from tests.components.homekit_controller.common import (
@ -58,6 +59,7 @@ async def test_koogeek_ls1_setup(hass):
# Assert that the friendly name is detected correctly
assert state.attributes["friendly_name"] == "Koogeek-SW2-187A91 - Real Time Energy"
assert state.attributes["unit_of_measurement"] == POWER_WATT
device_registry = dr.async_get(hass)