Don't include position in binary valve attributes (#107531)
This commit is contained in:
parent
bee76db1c3
commit
f18ab5e1cc
3 changed files with 74 additions and 8 deletions
|
@ -186,9 +186,10 @@ class ValveEntity(Entity):
|
|||
|
||||
@final
|
||||
@property
|
||||
def state_attributes(self) -> dict[str, Any]:
|
||||
def state_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return the state attributes."""
|
||||
|
||||
if not self.reports_position:
|
||||
return None
|
||||
return {ATTR_CURRENT_POSITION: self.current_valve_position}
|
||||
|
||||
@property
|
||||
|
|
56
tests/components/valve/snapshots/test_init.ambr
Normal file
56
tests/components/valve/snapshots/test_init.ambr
Normal file
|
@ -0,0 +1,56 @@
|
|||
# serializer version: 1
|
||||
# name: test_valve_setup
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Valve',
|
||||
'supported_features': <ValveEntityFeature: 3>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'valve.valve',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'open',
|
||||
})
|
||||
# ---
|
||||
# name: test_valve_setup.1
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'current_position': 50,
|
||||
'friendly_name': 'Valve',
|
||||
'supported_features': <ValveEntityFeature: 15>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'valve.valve_2',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'open',
|
||||
})
|
||||
# ---
|
||||
# name: test_valve_setup.2
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Valve',
|
||||
'restored': True,
|
||||
'supported_features': <ValveEntityFeature: 3>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'valve.valve',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unavailable',
|
||||
})
|
||||
# ---
|
||||
# name: test_valve_setup.3
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Valve',
|
||||
'restored': True,
|
||||
'supported_features': <ValveEntityFeature: 15>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'valve.valve_2',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'unavailable',
|
||||
})
|
||||
# ---
|
|
@ -2,6 +2,7 @@
|
|||
from collections.abc import Generator
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.valve import (
|
||||
DOMAIN,
|
||||
|
@ -193,26 +194,34 @@ def mock_config_entry(hass) -> tuple[MockConfigEntry, list[ValveEntity]]:
|
|||
|
||||
|
||||
async def test_valve_setup(
|
||||
hass: HomeAssistant, mock_config_entry: tuple[MockConfigEntry, list[ValveEntity]]
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: tuple[MockConfigEntry, list[ValveEntity]],
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test setup and tear down of valve platform and entity."""
|
||||
config_entry = mock_config_entry[0]
|
||||
|
||||
assert await hass.config_entries.async_setup(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
entity_id = mock_config_entry[1][0].entity_id
|
||||
|
||||
assert config_entry.state == ConfigEntryState.LOADED
|
||||
assert hass.states.get(entity_id)
|
||||
for entity in mock_config_entry[1]:
|
||||
entity_id = entity.entity_id
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state == snapshot
|
||||
|
||||
assert await hass.config_entries.async_unload(config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert config_entry.state == ConfigEntryState.NOT_LOADED
|
||||
entity_state = hass.states.get(entity_id)
|
||||
|
||||
assert entity_state
|
||||
assert entity_state.state == STATE_UNAVAILABLE
|
||||
for entity in mock_config_entry[1]:
|
||||
entity_id = entity.entity_id
|
||||
state = hass.states.get(entity_id)
|
||||
assert state
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
assert state == snapshot
|
||||
|
||||
|
||||
async def test_services(
|
||||
|
|
Loading…
Add table
Reference in a new issue