mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 13:27:09 +00:00
Render select entity unavailable when active feature is missing in Sensibo (#135031)
This commit is contained in:
parent
2704090418
commit
c5f80dd01d
@ -16,7 +16,6 @@ from homeassistant.components.select import (
|
||||
SelectEntityDescription,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.issue_registry import (
|
||||
@ -137,6 +136,13 @@ class SensiboSelect(SensiboDeviceBaseEntity, SelectEntity):
|
||||
self.entity_description = entity_description
|
||||
self._attr_unique_id = f"{device_id}-{entity_description.key}"
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Return True if entity is available."""
|
||||
if self.entity_description.key not in self.device_data.active_features:
|
||||
return False
|
||||
return super().available
|
||||
|
||||
@property
|
||||
def current_option(self) -> str | None:
|
||||
"""Return the current selected option."""
|
||||
@ -152,17 +158,6 @@ class SensiboSelect(SensiboDeviceBaseEntity, SelectEntity):
|
||||
|
||||
async def async_select_option(self, option: str) -> None:
|
||||
"""Set state to the selected option."""
|
||||
if self.entity_description.key not in self.device_data.active_features:
|
||||
hvac_mode = self.device_data.hvac_mode if self.device_data.hvac_mode else ""
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="select_option_not_available",
|
||||
translation_placeholders={
|
||||
"hvac_mode": hvac_mode,
|
||||
"key": self.entity_description.key,
|
||||
},
|
||||
)
|
||||
|
||||
await self.async_send_api_call(
|
||||
key=self.entity_description.data_key,
|
||||
value=option,
|
||||
|
@ -575,9 +575,6 @@
|
||||
"service_raised": {
|
||||
"message": "Could not perform action for {name} with error {error}"
|
||||
},
|
||||
"select_option_not_available": {
|
||||
"message": "Current mode {hvac_mode} doesn't support setting {key}"
|
||||
},
|
||||
"climate_react_not_available": {
|
||||
"message": "Use Sensibo Enable Climate React action once to enable switch or the Sensibo app"
|
||||
},
|
||||
|
@ -16,7 +16,7 @@ from homeassistant.components.select import (
|
||||
)
|
||||
from homeassistant.components.sensibo.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||
from homeassistant.const import ATTR_ENTITY_ID, STATE_UNAVAILABLE, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_registry as er, issue_registry as ir
|
||||
@ -63,7 +63,7 @@ async def test_select_set_option(
|
||||
"""Test the Sensibo select service."""
|
||||
|
||||
mock_client.async_get_devices_data.return_value.parsed[
|
||||
"ABC999111"
|
||||
"AAZZAAZZ"
|
||||
].active_features = [
|
||||
"timestamp",
|
||||
"on",
|
||||
@ -97,13 +97,11 @@ async def test_select_set_option(
|
||||
assert state.state == "on"
|
||||
|
||||
mock_client.async_get_devices_data.return_value.parsed[
|
||||
"ABC999111"
|
||||
"AAZZAAZZ"
|
||||
].active_features = [
|
||||
"timestamp",
|
||||
"on",
|
||||
"mode",
|
||||
"targetTemperature",
|
||||
"horizontalSwing",
|
||||
"light",
|
||||
]
|
||||
|
||||
@ -142,6 +140,21 @@ async def test_select_set_option(
|
||||
state = hass.states.get("select.kitchen_light")
|
||||
assert state.state == "dim"
|
||||
|
||||
mock_client.async_get_devices_data.return_value.parsed[
|
||||
"AAZZAAZZ"
|
||||
].active_features = [
|
||||
"timestamp",
|
||||
"on",
|
||||
"mode",
|
||||
]
|
||||
|
||||
freezer.tick(timedelta(minutes=5))
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("select.kitchen_light")
|
||||
assert state.state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"load_platforms",
|
||||
|
Loading…
x
Reference in New Issue
Block a user