mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Remove unknown from Shelly sensor state (#140597)
This commit is contained in:
parent
58ff593f96
commit
2fd91e7f9c
@ -374,9 +374,9 @@ SENSORS: dict[tuple[str, str], BlockSensorDescription] = {
|
||||
key="sensor|sensorOp",
|
||||
name="Operation",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
options=["unknown", "warmup", "normal", "fault"],
|
||||
options=["warmup", "normal", "fault"],
|
||||
translation_key="operation",
|
||||
value=lambda value: value,
|
||||
value=lambda value: None if value == "unknown" else value,
|
||||
extra_state_attributes=lambda block: {"self_test": block.selfTest},
|
||||
),
|
||||
("valve", "valve"): BlockSensorDescription(
|
||||
@ -391,8 +391,8 @@ SENSORS: dict[tuple[str, str], BlockSensorDescription] = {
|
||||
"failure",
|
||||
"opened",
|
||||
"opening",
|
||||
"unknown",
|
||||
],
|
||||
value=lambda value: None if value == "unknown" else value,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
removal_condition=lambda _, block: block.valve == "not_connected",
|
||||
),
|
||||
|
@ -106,7 +106,6 @@
|
||||
"state_attributes": {
|
||||
"detected": {
|
||||
"state": {
|
||||
"unknown": "Unknown",
|
||||
"none": "None",
|
||||
"mild": "Mild",
|
||||
"heavy": "Heavy",
|
||||
@ -141,7 +140,6 @@
|
||||
"sensor": {
|
||||
"operation": {
|
||||
"state": {
|
||||
"unknown": "Unknown",
|
||||
"warmup": "Warm-up",
|
||||
"normal": "Normal",
|
||||
"fault": "Fault"
|
||||
@ -164,8 +162,7 @@
|
||||
"closing": "Closing",
|
||||
"failure": "Failure",
|
||||
"opened": "Opened",
|
||||
"opening": "Opening",
|
||||
"unknown": "[%key:component::shelly::entity::sensor::operation::state::unknown%]"
|
||||
"opening": "Opening"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -134,11 +134,18 @@ MOCK_BLOCKS = [
|
||||
set_state=AsyncMock(side_effect=mock_light_set_state),
|
||||
),
|
||||
Mock(
|
||||
sensor_ids={"motion": 0, "temp": 22.1, "gas": "mild", "motionActive": 1},
|
||||
sensor_ids={
|
||||
"motion": 0,
|
||||
"temp": 22.1,
|
||||
"gas": "mild",
|
||||
"motionActive": 1,
|
||||
"sensorOp": "normal",
|
||||
},
|
||||
channel="0",
|
||||
motion=0,
|
||||
temp=22.1,
|
||||
gas="mild",
|
||||
sensorOp="normal",
|
||||
targetTemp=4,
|
||||
description="sensor_0",
|
||||
type="sensor",
|
||||
|
@ -345,14 +345,30 @@ async def test_block_sensor_without_value(
|
||||
assert hass.states.get(entity_id) is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("entity", "initial_state", "block_id", "attribute", "value"),
|
||||
[
|
||||
("test_name_battery", "98", DEVICE_BLOCK_ID, "battery", None),
|
||||
("test_name_operation", "normal", SENSOR_BLOCK_ID, "sensorOp", "unknown"),
|
||||
],
|
||||
)
|
||||
async def test_block_sensor_unknown_value(
|
||||
hass: HomeAssistant, mock_block_device: Mock, monkeypatch: pytest.MonkeyPatch
|
||||
hass: HomeAssistant,
|
||||
mock_block_device: Mock,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
entity: str,
|
||||
initial_state: str,
|
||||
block_id: int,
|
||||
attribute: str,
|
||||
value: str | None,
|
||||
) -> None:
|
||||
"""Test block sensor unknown value."""
|
||||
entity_id = f"{SENSOR_DOMAIN}.test_name_battery"
|
||||
entity_id = f"{SENSOR_DOMAIN}.{entity}"
|
||||
await init_integration(hass, 1)
|
||||
|
||||
monkeypatch.setattr(mock_block_device.blocks[DEVICE_BLOCK_ID], "battery", None)
|
||||
assert hass.states.get(entity_id).state == initial_state
|
||||
|
||||
monkeypatch.setattr(mock_block_device.blocks[block_id], attribute, value)
|
||||
mock_block_device.mock_update()
|
||||
|
||||
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
||||
|
Loading…
x
Reference in New Issue
Block a user