Add missing unit for signal strength (#40436)
* Added missing unit for signal strength * Added one more unit * Replaced string with variable * Fixed wrong import * Fix import * Replaced string with variable * Fixed wrong import * Apply suggestions from code review * Black * Again a fix :-( * iSort * iSort after merge Co-authored-by: springstan <46536646+springstan@users.noreply.github.com>
This commit is contained in:
1 parent
480066ba63
commit
7554c8d6c5
15 files changed
+84
-27
No files matched your search
@@ -15,6 +15,7 @@ from homeassistant.const import (
|
||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.setup import async_setup_component
|
||||
@@ -187,7 +188,7 @@ async def test_sensors_flex(hass, canary) -> None:
|
||||
"home_dining_room_wifi": (
|
||||
"20_wifi",
|
||||
"-57.0",
|
||||
"dBm",
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||
None,
|
||||
),
|
||||
|
||||
@@ -3,11 +3,19 @@
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.huawei_lte import sensor
|
||||
from homeassistant.const import (
|
||||
SIGNAL_STRENGTH_DECIBELS,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value", "expected"),
|
||||
(("-71 dBm", (-71, "dBm")), ("15dB", (15, "dB")), (">=-51dBm", (-51, "dBm"))),
|
||||
(
|
||||
("-71 dBm", (-71, SIGNAL_STRENGTH_DECIBELS_MILLIWATT)),
|
||||
("15dB", (15, SIGNAL_STRENGTH_DECIBELS)),
|
||||
(">=-51dBm", (-51, SIGNAL_STRENGTH_DECIBELS_MILLIWATT)),
|
||||
),
|
||||
)
|
||||
def test_format_default(value, expected):
|
||||
"""Test that default formatter copes with expected values."""
|
||||
|
||||
@@ -3,7 +3,12 @@ import pytest
|
||||
|
||||
from homeassistant.components.rfxtrx import DOMAIN
|
||||
from homeassistant.components.rfxtrx.const import ATTR_EVENT
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, PERCENTAGE, TEMP_CELSIUS
|
||||
from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
TEMP_CELSIUS,
|
||||
)
|
||||
from homeassistant.core import State
|
||||
|
||||
from tests.common import MockConfigEntry, mock_restore_cache
|
||||
@@ -100,7 +105,10 @@ async def test_one_sensor_no_datatype(hass, rfxtrx):
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == f"{base_name} Rssi numeric"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "dBm"
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||
)
|
||||
|
||||
state = hass.states.get(f"{base_id}_battery_numeric")
|
||||
assert state
|
||||
@@ -174,7 +182,10 @@ async def test_discover_sensor(hass, rfxtrx_automatic):
|
||||
state = hass.states.get(f"{base_id}_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "-64"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "dBm"
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||
)
|
||||
|
||||
state = hass.states.get(f"{base_id}_temperature")
|
||||
assert state
|
||||
@@ -203,7 +214,10 @@ async def test_discover_sensor(hass, rfxtrx_automatic):
|
||||
state = hass.states.get(f"{base_id}_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "-64"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "dBm"
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||
)
|
||||
|
||||
state = hass.states.get(f"{base_id}_temperature")
|
||||
assert state
|
||||
@@ -232,7 +246,10 @@ async def test_discover_sensor(hass, rfxtrx_automatic):
|
||||
state = hass.states.get(f"{base_id}_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "-64"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "dBm"
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||
)
|
||||
|
||||
state = hass.states.get(f"{base_id}_temperature")
|
||||
assert state
|
||||
@@ -315,13 +332,19 @@ async def test_rssi_sensor(hass, rfxtrx):
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == "PT2262 22670e Rssi numeric"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "dBm"
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||
)
|
||||
|
||||
state = hass.states.get("sensor.ac_213c7f2_48_rssi_numeric")
|
||||
assert state
|
||||
assert state.state == "unknown"
|
||||
assert state.attributes.get("friendly_name") == "AC 213c7f2:48 Rssi numeric"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == "dBm"
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||
)
|
||||
|
||||
await rfxtrx.signal("0913000022670e013b70")
|
||||
await rfxtrx.signal("0b1100cd0213c7f230010f71")
|
||||
|
||||
@@ -12,7 +12,6 @@ from homeassistant.components.wled.const import (
|
||||
ATTR_MAX_POWER,
|
||||
CURRENT_MA,
|
||||
DOMAIN,
|
||||
SIGNAL_DBM,
|
||||
)
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
@@ -20,6 +19,7 @@ from homeassistant.const import (
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
DATA_BYTES,
|
||||
PERCENTAGE,
|
||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import dt as dt_util
|
||||
@@ -138,7 +138,10 @@ async def test_sensors(
|
||||
state = hass.states.get("sensor.wled_rgb_light_wifi_rssi")
|
||||
assert state
|
||||
assert state.attributes.get(ATTR_ICON) == "mdi:wifi"
|
||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SIGNAL_DBM
|
||||
assert (
|
||||
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||
== SIGNAL_STRENGTH_DECIBELS_MILLIWATT
|
||||
)
|
||||
assert state.state == "-62"
|
||||
|
||||
entry = registry.async_get("sensor.wled_rgb_light_wifi_rssi")
|
||||
|
||||
Reference in new issue
Block a user