Skip to content

Commit c5f80dd

Browse files
Render select entity unavailable when active feature is missing in Sensibo (home-assistant#135031)
1 parent 2704090 commit c5f80dd

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

homeassistant/components/sensibo/select.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
SelectEntityDescription,
1717
)
1818
from homeassistant.core import HomeAssistant
19-
from homeassistant.exceptions import HomeAssistantError
2019
from homeassistant.helpers import entity_registry as er
2120
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2221
from homeassistant.helpers.issue_registry import (
@@ -137,6 +136,13 @@ def __init__(
137136
self.entity_description = entity_description
138137
self._attr_unique_id = f"{device_id}-{entity_description.key}"
139138

139+
@property
140+
def available(self) -> bool:
141+
"""Return True if entity is available."""
142+
if self.entity_description.key not in self.device_data.active_features:
143+
return False
144+
return super().available
145+
140146
@property
141147
def current_option(self) -> str | None:
142148
"""Return the current selected option."""
@@ -152,17 +158,6 @@ def options(self) -> list[str]:
152158

153159
async def async_select_option(self, option: str) -> None:
154160
"""Set state to the selected option."""
155-
if self.entity_description.key not in self.device_data.active_features:
156-
hvac_mode = self.device_data.hvac_mode if self.device_data.hvac_mode else ""
157-
raise HomeAssistantError(
158-
translation_domain=DOMAIN,
159-
translation_key="select_option_not_available",
160-
translation_placeholders={
161-
"hvac_mode": hvac_mode,
162-
"key": self.entity_description.key,
163-
},
164-
)
165-
166161
await self.async_send_api_call(
167162
key=self.entity_description.data_key,
168163
value=option,

homeassistant/components/sensibo/strings.json

-3
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,6 @@
575575
"service_raised": {
576576
"message": "Could not perform action for {name} with error {error}"
577577
},
578-
"select_option_not_available": {
579-
"message": "Current mode {hvac_mode} doesn't support setting {key}"
580-
},
581578
"climate_react_not_available": {
582579
"message": "Use Sensibo Enable Climate React action once to enable switch or the Sensibo app"
583580
},

tests/components/sensibo/test_select.py

+18-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from homeassistant.components.sensibo.const import DOMAIN
1818
from homeassistant.config_entries import ConfigEntry
19-
from homeassistant.const import ATTR_ENTITY_ID, Platform
19+
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, Platform
2020
from homeassistant.core import HomeAssistant
2121
from homeassistant.exceptions import HomeAssistantError
2222
from homeassistant.helpers import entity_registry as er, issue_registry as ir
@@ -63,7 +63,7 @@ async def test_select_set_option(
6363
"""Test the Sensibo select service."""
6464

6565
mock_client.async_get_devices_data.return_value.parsed[
66-
"ABC999111"
66+
"AAZZAAZZ"
6767
].active_features = [
6868
"timestamp",
6969
"on",
@@ -97,13 +97,11 @@ async def test_select_set_option(
9797
assert state.state == "on"
9898

9999
mock_client.async_get_devices_data.return_value.parsed[
100-
"ABC999111"
100+
"AAZZAAZZ"
101101
].active_features = [
102102
"timestamp",
103103
"on",
104104
"mode",
105-
"targetTemperature",
106-
"horizontalSwing",
107105
"light",
108106
]
109107

@@ -142,6 +140,21 @@ async def test_select_set_option(
142140
state = hass.states.get("select.kitchen_light")
143141
assert state.state == "dim"
144142

143+
mock_client.async_get_devices_data.return_value.parsed[
144+
"AAZZAAZZ"
145+
].active_features = [
146+
"timestamp",
147+
"on",
148+
"mode",
149+
]
150+
151+
freezer.tick(timedelta(minutes=5))
152+
async_fire_time_changed(hass)
153+
await hass.async_block_till_done()
154+
155+
state = hass.states.get("select.kitchen_light")
156+
assert state.state == STATE_UNAVAILABLE
157+
145158

146159
@pytest.mark.parametrize(
147160
"load_platforms",

0 commit comments

Comments
 (0)