mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Track code coverage for ZHA sensor entities (#76617)
* Track code coverage for ZHA sensor entities * remove correct entry
This commit is contained in:
parent
75ca80428d
commit
3937ac2ca3
@ -1538,7 +1538,6 @@ omit =
|
||||
homeassistant/components/zha/core/registries.py
|
||||
homeassistant/components/zha/entity.py
|
||||
homeassistant/components/zha/light.py
|
||||
homeassistant/components/zha/sensor.py
|
||||
homeassistant/components/zhong_hong/climate.py
|
||||
homeassistant/components/ziggo_mediabox_xl/media_player.py
|
||||
homeassistant/components/zoneminder/*
|
||||
|
@ -183,7 +183,7 @@ class Sensor(ZhaEntity, SensorEntity):
|
||||
"""Handle state update from channel."""
|
||||
self.async_write_ha_state()
|
||||
|
||||
def formatter(self, value: int) -> int | float:
|
||||
def formatter(self, value: int) -> int | float | None:
|
||||
"""Numeric pass-through formatter."""
|
||||
if self._decimals > 0:
|
||||
return round(
|
||||
@ -236,11 +236,11 @@ class Battery(Sensor):
|
||||
return cls(unique_id, zha_device, channels, **kwargs)
|
||||
|
||||
@staticmethod
|
||||
def formatter(value: int) -> int: # pylint: disable=arguments-differ
|
||||
def formatter(value: int) -> int | None: # pylint: disable=arguments-differ
|
||||
"""Return the state of the entity."""
|
||||
# per zcl specs battery percent is reported at 200% ¯\_(ツ)_/¯
|
||||
if not isinstance(value, numbers.Number) or value == -1:
|
||||
return value
|
||||
return None
|
||||
value = round(value / 2)
|
||||
return value
|
||||
|
||||
|
@ -255,6 +255,17 @@ async def async_test_powerconfiguration(hass, cluster, entity_id):
|
||||
assert hass.states.get(entity_id).attributes["battery_voltage"] == 2.0
|
||||
|
||||
|
||||
async def async_test_powerconfiguration2(hass, cluster, entity_id):
|
||||
"""Test powerconfiguration/battery sensor."""
|
||||
await send_attributes_report(hass, cluster, {33: -1})
|
||||
assert_state(hass, entity_id, STATE_UNKNOWN, "%")
|
||||
assert hass.states.get(entity_id).attributes["battery_voltage"] == 2.9
|
||||
assert hass.states.get(entity_id).attributes["battery_quantity"] == 3
|
||||
assert hass.states.get(entity_id).attributes["battery_size"] == "AAA"
|
||||
await send_attributes_report(hass, cluster, {32: 20})
|
||||
assert hass.states.get(entity_id).attributes["battery_voltage"] == 2.0
|
||||
|
||||
|
||||
async def async_test_device_temperature(hass, cluster, entity_id):
|
||||
"""Test temperature sensor."""
|
||||
await send_attributes_report(hass, cluster, {0: 2900})
|
||||
@ -370,6 +381,18 @@ async def async_test_device_temperature(hass, cluster, entity_id):
|
||||
},
|
||||
None,
|
||||
),
|
||||
(
|
||||
general.PowerConfiguration.cluster_id,
|
||||
"battery",
|
||||
async_test_powerconfiguration2,
|
||||
2,
|
||||
{
|
||||
"battery_size": 4, # AAA
|
||||
"battery_voltage": 29,
|
||||
"battery_quantity": 3,
|
||||
},
|
||||
None,
|
||||
),
|
||||
(
|
||||
general.DeviceTemperature.cluster_id,
|
||||
"device_temperature",
|
||||
|
Loading…
x
Reference in New Issue
Block a user