mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Add dedicated sensors for extra_state_attributes in Shelly integration (#140793)
* Add dedicated sensors for extra_state_attributes in Shelly integration * add tests * apply review comment * fix text syntax * add gas test * update strings * add icons
This commit is contained in:
parent
30c19ec373
commit
12f5bd2aea
@ -23,12 +23,18 @@
|
|||||||
"gas_concentration": {
|
"gas_concentration": {
|
||||||
"default": "mdi:gauge"
|
"default": "mdi:gauge"
|
||||||
},
|
},
|
||||||
|
"gas_detected": {
|
||||||
|
"default": "mdi:gas-burner"
|
||||||
|
},
|
||||||
"lamp_life": {
|
"lamp_life": {
|
||||||
"default": "mdi:progress-wrench"
|
"default": "mdi:progress-wrench"
|
||||||
},
|
},
|
||||||
"operation": {
|
"operation": {
|
||||||
"default": "mdi:cog-transfer"
|
"default": "mdi:cog-transfer"
|
||||||
},
|
},
|
||||||
|
"self_test": {
|
||||||
|
"default": "mdi:progress-wrench"
|
||||||
|
},
|
||||||
"tilt": {
|
"tilt": {
|
||||||
"default": "mdi:angle-acute"
|
"default": "mdi:angle-acute"
|
||||||
},
|
},
|
||||||
|
@ -397,6 +397,28 @@ SENSORS: dict[tuple[str, str], BlockSensorDescription] = {
|
|||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
removal_condition=lambda _, block: block.valve == "not_connected",
|
removal_condition=lambda _, block: block.valve == "not_connected",
|
||||||
),
|
),
|
||||||
|
("sensor", "gas"): BlockSensorDescription(
|
||||||
|
key="sensor|gas",
|
||||||
|
name="Gas detected",
|
||||||
|
translation_key="gas_detected",
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
options=[
|
||||||
|
"none",
|
||||||
|
"mild",
|
||||||
|
"heavy",
|
||||||
|
"test",
|
||||||
|
],
|
||||||
|
value=lambda value: None if value == "unknown" else value,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
|
("sensor", "selfTest"): BlockSensorDescription(
|
||||||
|
key="sensor|selfTest",
|
||||||
|
name="Self test",
|
||||||
|
translation_key="self_test",
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
options=["not_completed", "completed", "running", "pending"],
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
REST_SENSORS: Final = {
|
REST_SENSORS: Final = {
|
||||||
|
@ -138,6 +138,24 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
|
"gas_detected": {
|
||||||
|
"state": {
|
||||||
|
"none": "None",
|
||||||
|
"mild": "Mild",
|
||||||
|
"heavy": "Heavy",
|
||||||
|
"test": "Test"
|
||||||
|
},
|
||||||
|
"state_attributes": {
|
||||||
|
"options": {
|
||||||
|
"state": {
|
||||||
|
"none": "[%key:component::shelly::entity::sensor::gas_detected::state::none%]",
|
||||||
|
"mild": "[%key:component::shelly::entity::sensor::gas_detected::state::mild%]",
|
||||||
|
"heavy": "[%key:component::shelly::entity::sensor::gas_detected::state::heavy%]",
|
||||||
|
"test": "[%key:component::shelly::entity::sensor::gas_detected::state::test%]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"operation": {
|
"operation": {
|
||||||
"state": {
|
"state": {
|
||||||
"warmup": "Warm-up",
|
"warmup": "Warm-up",
|
||||||
@ -155,6 +173,24 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"self_test": {
|
||||||
|
"state": {
|
||||||
|
"not_completed": "Not completed",
|
||||||
|
"completed": "Completed",
|
||||||
|
"running": "Running",
|
||||||
|
"pending": "Pending"
|
||||||
|
},
|
||||||
|
"state_attributes": {
|
||||||
|
"options": {
|
||||||
|
"state": {
|
||||||
|
"not_completed": "[%key:component::shelly::entity::sensor::self_test::state::not_completed%]",
|
||||||
|
"completed": "[%key:component::shelly::entity::sensor::self_test::state::completed%]",
|
||||||
|
"running": "[%key:component::shelly::entity::sensor::self_test::state::running%]",
|
||||||
|
"pending": "[%key:component::shelly::entity::sensor::self_test::state::pending%]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"valve_status": {
|
"valve_status": {
|
||||||
"state": {
|
"state": {
|
||||||
"checking": "Checking",
|
"checking": "Checking",
|
||||||
|
@ -142,12 +142,14 @@ MOCK_BLOCKS = [
|
|||||||
"gas": "mild",
|
"gas": "mild",
|
||||||
"motionActive": 1,
|
"motionActive": 1,
|
||||||
"sensorOp": "normal",
|
"sensorOp": "normal",
|
||||||
|
"selfTest": "pending",
|
||||||
},
|
},
|
||||||
channel="0",
|
channel="0",
|
||||||
motion=0,
|
motion=0,
|
||||||
temp=22.1,
|
temp=22.1,
|
||||||
gas="mild",
|
gas="mild",
|
||||||
sensorOp="normal",
|
sensorOp="normal",
|
||||||
|
selfTest="pending",
|
||||||
targetTemp=4,
|
targetTemp=4,
|
||||||
description="sensor_0",
|
description="sensor_0",
|
||||||
type="sensor",
|
type="sensor",
|
||||||
|
@ -346,13 +346,44 @@ async def test_block_sensor_without_value(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("entity", "initial_state", "block_id", "attribute", "value"),
|
("entity", "initial_state", "block_id", "attribute", "value", "final_value"),
|
||||||
[
|
[
|
||||||
("test_name_battery", "98", DEVICE_BLOCK_ID, "battery", None),
|
("test_name_battery", "98", DEVICE_BLOCK_ID, "battery", None, STATE_UNKNOWN),
|
||||||
("test_name_operation", "normal", SENSOR_BLOCK_ID, "sensorOp", "unknown"),
|
(
|
||||||
|
"test_name_operation",
|
||||||
|
"normal",
|
||||||
|
SENSOR_BLOCK_ID,
|
||||||
|
"sensorOp",
|
||||||
|
None,
|
||||||
|
STATE_UNKNOWN,
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"test_name_operation",
|
||||||
|
"normal",
|
||||||
|
SENSOR_BLOCK_ID,
|
||||||
|
"sensorOp",
|
||||||
|
"normal",
|
||||||
|
"normal",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"test_name_self_test",
|
||||||
|
"pending",
|
||||||
|
SENSOR_BLOCK_ID,
|
||||||
|
"selfTest",
|
||||||
|
"completed",
|
||||||
|
"completed",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"test_name_gas_detected",
|
||||||
|
"mild",
|
||||||
|
SENSOR_BLOCK_ID,
|
||||||
|
"gas",
|
||||||
|
"heavy",
|
||||||
|
"heavy",
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_block_sensor_unknown_value(
|
async def test_block_sensor_values(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
mock_block_device: Mock,
|
mock_block_device: Mock,
|
||||||
monkeypatch: pytest.MonkeyPatch,
|
monkeypatch: pytest.MonkeyPatch,
|
||||||
@ -361,6 +392,7 @@ async def test_block_sensor_unknown_value(
|
|||||||
block_id: int,
|
block_id: int,
|
||||||
attribute: str,
|
attribute: str,
|
||||||
value: str | None,
|
value: str | None,
|
||||||
|
final_value: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test block sensor unknown value."""
|
"""Test block sensor unknown value."""
|
||||||
entity_id = f"{SENSOR_DOMAIN}.{entity}"
|
entity_id = f"{SENSOR_DOMAIN}.{entity}"
|
||||||
@ -371,7 +403,7 @@ async def test_block_sensor_unknown_value(
|
|||||||
monkeypatch.setattr(mock_block_device.blocks[block_id], attribute, value)
|
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 == final_value
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user