Skip to content

Commit

Permalink
Don't include position in binary valve attributes (#107531)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored and frenck committed Jan 12, 2024
1 parent bee76db commit f18ab5e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
5 changes: 3 additions & 2 deletions homeassistant/components/valve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ def state(self) -> str | None:

@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
Expand Down
56 changes: 56 additions & 0 deletions tests/components/valve/snapshots/test_init.ambr
Original file line number Diff line number Diff line change
@@ -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',
})
# ---
21 changes: 15 additions & 6 deletions tests/components/valve/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from collections.abc import Generator

import pytest
from syrupy.assertion import SnapshotAssertion

from homeassistant.components.valve import (
DOMAIN,
Expand Down Expand Up @@ -193,26 +194,34 @@ async def async_setup_entry_platform(


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(
Expand Down

0 comments on commit f18ab5e

Please sign in to comment.