mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +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",
|
key="sensor|sensorOp",
|
||||||
name="Operation",
|
name="Operation",
|
||||||
device_class=SensorDeviceClass.ENUM,
|
device_class=SensorDeviceClass.ENUM,
|
||||||
options=["unknown", "warmup", "normal", "fault"],
|
options=["warmup", "normal", "fault"],
|
||||||
translation_key="operation",
|
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},
|
extra_state_attributes=lambda block: {"self_test": block.selfTest},
|
||||||
),
|
),
|
||||||
("valve", "valve"): BlockSensorDescription(
|
("valve", "valve"): BlockSensorDescription(
|
||||||
@ -391,8 +391,8 @@ SENSORS: dict[tuple[str, str], BlockSensorDescription] = {
|
|||||||
"failure",
|
"failure",
|
||||||
"opened",
|
"opened",
|
||||||
"opening",
|
"opening",
|
||||||
"unknown",
|
|
||||||
],
|
],
|
||||||
|
value=lambda value: None if value == "unknown" else value,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
removal_condition=lambda _, block: block.valve == "not_connected",
|
removal_condition=lambda _, block: block.valve == "not_connected",
|
||||||
),
|
),
|
||||||
|
@ -106,7 +106,6 @@
|
|||||||
"state_attributes": {
|
"state_attributes": {
|
||||||
"detected": {
|
"detected": {
|
||||||
"state": {
|
"state": {
|
||||||
"unknown": "Unknown",
|
|
||||||
"none": "None",
|
"none": "None",
|
||||||
"mild": "Mild",
|
"mild": "Mild",
|
||||||
"heavy": "Heavy",
|
"heavy": "Heavy",
|
||||||
@ -141,7 +140,6 @@
|
|||||||
"sensor": {
|
"sensor": {
|
||||||
"operation": {
|
"operation": {
|
||||||
"state": {
|
"state": {
|
||||||
"unknown": "Unknown",
|
|
||||||
"warmup": "Warm-up",
|
"warmup": "Warm-up",
|
||||||
"normal": "Normal",
|
"normal": "Normal",
|
||||||
"fault": "Fault"
|
"fault": "Fault"
|
||||||
@ -164,8 +162,7 @@
|
|||||||
"closing": "Closing",
|
"closing": "Closing",
|
||||||
"failure": "Failure",
|
"failure": "Failure",
|
||||||
"opened": "Opened",
|
"opened": "Opened",
|
||||||
"opening": "Opening",
|
"opening": "Opening"
|
||||||
"unknown": "[%key:component::shelly::entity::sensor::operation::state::unknown%]"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,11 +134,18 @@ MOCK_BLOCKS = [
|
|||||||
set_state=AsyncMock(side_effect=mock_light_set_state),
|
set_state=AsyncMock(side_effect=mock_light_set_state),
|
||||||
),
|
),
|
||||||
Mock(
|
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",
|
channel="0",
|
||||||
motion=0,
|
motion=0,
|
||||||
temp=22.1,
|
temp=22.1,
|
||||||
gas="mild",
|
gas="mild",
|
||||||
|
sensorOp="normal",
|
||||||
targetTemp=4,
|
targetTemp=4,
|
||||||
description="sensor_0",
|
description="sensor_0",
|
||||||
type="sensor",
|
type="sensor",
|
||||||
|
@ -345,14 +345,30 @@ async def test_block_sensor_without_value(
|
|||||||
assert hass.states.get(entity_id) is None
|
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(
|
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:
|
) -> None:
|
||||||
"""Test block sensor unknown value."""
|
"""Test block sensor unknown value."""
|
||||||
entity_id = f"{SENSOR_DOMAIN}.test_name_battery"
|
entity_id = f"{SENSOR_DOMAIN}.{entity}"
|
||||||
await init_integration(hass, 1)
|
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()
|
mock_block_device.mock_update()
|
||||||
|
|
||||||
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
assert hass.states.get(entity_id).state == STATE_UNKNOWN
|
||||||
|
Loading…
x
Reference in New Issue
Block a user