Fix YoLink valve state when device running in class A mode (#150456)

This commit is contained in:
Matrix
2025-08-12 16:42:40 +08:00
committed by Franck Nijhof
parent 2725abf032
commit fed6f19edf
2 changed files with 11 additions and 6 deletions

View File

@@ -47,6 +47,9 @@
"exceptions": { "exceptions": {
"invalid_config_entry": { "invalid_config_entry": {
"message": "Config entry not found or not loaded!" "message": "Config entry not found or not loaded!"
},
"valve_inoperable_currently": {
"message": "The Valve cannot be operated currently."
} }
}, },
"entity": { "entity": {

View File

@@ -21,6 +21,7 @@ from homeassistant.components.valve import (
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import DEV_MODEL_WATER_METER_YS5007, DOMAIN from .const import DEV_MODEL_WATER_METER_YS5007, DOMAIN
@@ -130,6 +131,13 @@ class YoLinkValveEntity(YoLinkEntity, ValveEntity):
async def _async_invoke_device(self, state: str) -> None: async def _async_invoke_device(self, state: str) -> None:
"""Call setState api to change valve state.""" """Call setState api to change valve state."""
if (
self.coordinator.device.is_support_mode_switching()
and self.coordinator.dev_net_type == ATTR_DEVICE_MODEL_A
):
raise HomeAssistantError(
translation_domain=DOMAIN, translation_key="valve_inoperable_currently"
)
if ( if (
self.coordinator.device.device_type self.coordinator.device.device_type
== ATTR_DEVICE_MULTI_WATER_METER_CONTROLLER == ATTR_DEVICE_MULTI_WATER_METER_CONTROLLER
@@ -155,10 +163,4 @@ class YoLinkValveEntity(YoLinkEntity, ValveEntity):
@property @property
def available(self) -> bool: def available(self) -> bool:
"""Return true is device is available.""" """Return true is device is available."""
if (
self.coordinator.device.is_support_mode_switching()
and self.coordinator.dev_net_type is not None
):
# When the device operates in Class A mode, it cannot be controlled.
return self.coordinator.dev_net_type != ATTR_DEVICE_MODEL_A
return super().available return super().available