Fix mysensors battery level attribute (#101868)
parent
8e3c665fd3
commit
52067dbfe5
|
@ -8,7 +8,7 @@ from typing import Any
|
|||
from mysensors import BaseAsyncGateway, Sensor
|
||||
from mysensors.sensor import ChildSensor
|
||||
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.debounce import Debouncer
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
|
@ -212,6 +212,8 @@ class MySensorsChildEntity(MySensorNodeEntity):
|
|||
|
||||
attr[ATTR_CHILD_ID] = self.child_id
|
||||
attr[ATTR_DESCRIPTION] = self._child.description
|
||||
# We should deprecate the battery level attribute in the future.
|
||||
attr[ATTR_BATTERY_LEVEL] = self._node.battery_level
|
||||
|
||||
set_req = self.gateway.const.SetReq
|
||||
for value_type, value in self._values.items():
|
||||
|
|
|
@ -6,7 +6,7 @@ from collections.abc import Callable
|
|||
from mysensors.sensor import Sensor
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from homeassistant.const import ATTR_DEVICE_CLASS
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_DEVICE_CLASS
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
|
@ -23,6 +23,7 @@ async def test_door_sensor(
|
|||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.DOOR
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
receive_message("1;1;1;0;16;1\n")
|
||||
await hass.async_block_till_done()
|
||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.components.climate import (
|
|||
SERVICE_SET_TEMPERATURE,
|
||||
HVACMode,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
|
@ -36,6 +36,7 @@ async def test_hvac_node_auto(
|
|||
|
||||
assert state
|
||||
assert state.state == HVACMode.OFF
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
# Test set hvac mode auto
|
||||
await hass.services.async_call(
|
||||
|
@ -150,6 +151,7 @@ async def test_hvac_node_heat(
|
|||
|
||||
assert state
|
||||
assert state.state == HVACMode.OFF
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
# Test set hvac mode heat
|
||||
await hass.services.async_call(
|
||||
|
@ -259,6 +261,7 @@ async def test_hvac_node_cool(
|
|||
|
||||
assert state
|
||||
assert state.state == HVACMode.OFF
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
# Test set hvac mode heat
|
||||
await hass.services.async_call(
|
||||
|
|
|
@ -19,7 +19,7 @@ from homeassistant.components.cover import (
|
|||
STATE_OPEN,
|
||||
STATE_OPENING,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
|
@ -37,6 +37,7 @@ async def test_cover_node_percentage(
|
|||
assert state
|
||||
assert state.state == STATE_CLOSED
|
||||
assert state.attributes[ATTR_CURRENT_POSITION] == 0
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
COVER_DOMAIN,
|
||||
|
|
|
@ -6,7 +6,12 @@ from collections.abc import Callable
|
|||
from mysensors.sensor import Sensor
|
||||
|
||||
from homeassistant.components.device_tracker import ATTR_SOURCE_TYPE, SourceType
|
||||
from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, STATE_NOT_HOME
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL,
|
||||
ATTR_LATITUDE,
|
||||
ATTR_LONGITUDE,
|
||||
STATE_NOT_HOME,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
|
@ -32,6 +37,7 @@ async def test_gps_sensor(
|
|||
assert state.attributes[ATTR_SOURCE_TYPE] == SourceType.GPS
|
||||
assert state.attributes[ATTR_LATITUDE] == float(latitude)
|
||||
assert state.attributes[ATTR_LONGITUDE] == float(longitude)
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
latitude = "40.782"
|
||||
longitude = "-73.965"
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.components.light import (
|
|||
ATTR_RGBW_COLOR,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
)
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
|
@ -28,6 +29,7 @@ async def test_dimmer_node(
|
|||
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
# Test turn on
|
||||
await hass.services.async_call(
|
||||
|
@ -108,6 +110,7 @@ async def test_rgb_node(
|
|||
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
# Test turn on
|
||||
await hass.services.async_call(
|
||||
|
@ -218,6 +221,7 @@ async def test_rgbw_node(
|
|||
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
# Test turn on
|
||||
await hass.services.async_call(
|
||||
|
|
|
@ -14,7 +14,12 @@ from homeassistant.components.remote import (
|
|||
SERVICE_LEARN_COMMAND,
|
||||
SERVICE_SEND_COMMAND,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL,
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_TURN_OFF,
|
||||
SERVICE_TURN_ON,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
|
@ -31,6 +36,7 @@ async def test_ir_transceiver(
|
|||
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
# Test turn on
|
||||
await hass.services.async_call(
|
||||
|
|
|
@ -12,6 +12,7 @@ from homeassistant.components.sensor import (
|
|||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL,
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ICON,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
|
@ -41,6 +42,7 @@ async def test_gps_sensor(
|
|||
|
||||
assert state
|
||||
assert state.state == "40.741894,-73.989311,12"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
altitude = 0
|
||||
new_coords = "40.782,-73.965"
|
||||
|
@ -67,6 +69,7 @@ async def test_ir_transceiver(
|
|||
|
||||
assert state
|
||||
assert state.state == "test_code"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
receive_message("1;1;1;0;50;new_code\n")
|
||||
await hass.async_block_till_done()
|
||||
|
@ -87,6 +90,7 @@ async def test_battery_entity(
|
|||
state = hass.states.get(battery_entity_id)
|
||||
assert state
|
||||
assert state.state == "42"
|
||||
assert ATTR_BATTERY_LEVEL not in state.attributes
|
||||
|
||||
receive_message("1;255;3;0;0;84\n")
|
||||
await hass.async_block_till_done()
|
||||
|
@ -94,6 +98,7 @@ async def test_battery_entity(
|
|||
state = hass.states.get(battery_entity_id)
|
||||
assert state
|
||||
assert state.state == "84"
|
||||
assert ATTR_BATTERY_LEVEL not in state.attributes
|
||||
|
||||
|
||||
async def test_power_sensor(
|
||||
|
@ -111,6 +116,7 @@ async def test_power_sensor(
|
|||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.POWER
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfPower.WATT
|
||||
assert state.attributes[ATTR_STATE_CLASS] is SensorStateClass.MEASUREMENT
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
|
||||
async def test_energy_sensor(
|
||||
|
@ -128,6 +134,7 @@ async def test_energy_sensor(
|
|||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.ENERGY
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == UnitOfEnergy.KILO_WATT_HOUR
|
||||
assert state.attributes[ATTR_STATE_CLASS] is SensorStateClass.TOTAL_INCREASING
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
|
||||
async def test_sound_sensor(
|
||||
|
@ -144,6 +151,7 @@ async def test_sound_sensor(
|
|||
assert state.state == "10"
|
||||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.SOUND_PRESSURE
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "dB"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
|
||||
async def test_distance_sensor(
|
||||
|
@ -161,6 +169,7 @@ async def test_distance_sensor(
|
|||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.DISTANCE
|
||||
assert ATTR_ICON not in state.attributes
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == "cm"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
@ -193,3 +202,4 @@ async def test_temperature_sensor(
|
|||
assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TEMPERATURE
|
||||
assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == unit
|
||||
assert state.attributes[ATTR_STATE_CLASS] is SensorStateClass.MEASUREMENT
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
|
|
@ -7,6 +7,7 @@ from unittest.mock import MagicMock, call
|
|||
from mysensors.sensor import Sensor
|
||||
|
||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
|
@ -23,6 +24,7 @@ async def test_relay_node(
|
|||
|
||||
assert state
|
||||
assert state.state == "off"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
SWITCH_DOMAIN,
|
||||
|
|
|
@ -12,7 +12,7 @@ from homeassistant.components.text import (
|
|||
DOMAIN as TEXT_DOMAIN,
|
||||
SERVICE_SET_VALUE,
|
||||
)
|
||||
from homeassistant.const import ATTR_ENTITY_ID
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, ATTR_ENTITY_ID
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
|
||||
|
@ -29,6 +29,7 @@ async def test_text_node(
|
|||
|
||||
assert state
|
||||
assert state.state == "test"
|
||||
assert state.attributes[ATTR_BATTERY_LEVEL] == 0
|
||||
|
||||
await hass.services.async_call(
|
||||
TEXT_DOMAIN,
|
||||
|
|
Loading…
Reference in New Issue