Add support for YS7914#159586
Conversation
joostlek
left a comment
There was a problem hiding this comment.
Can we please bump the dependency in a separate PR?
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
| @@ -41,15 +41,16 @@ class YoLinkBinarySensorEntityDescription(BinarySensorEntityDescription): | |||
| """YoLink BinarySensorEntityDescription.""" | |||
There was a problem hiding this comment.
If you add kw_only=True to the dataclass decorator, you can omit the defaults
| def parse_data_leak_sensor_state(device: YoLinkDevice, data: dict) -> bool | None: | ||
| """Parse leak sensor state.""" | ||
| if device.device_type == ATTR_DEVICE_MULTI_CAPS_LEAK_SENSOR: | ||
| if (state := data.get("state")) is None or ( | ||
| value := state.get("waterDetection") | ||
| ) is None: | ||
| return None | ||
| return ( | ||
| value == "normal" | ||
| if data.get("waterDetectionMode") == "WaterPeak" | ||
| else value == "leak" | ||
| ) | ||
| return data.get("state") in ["alert", "full"] | ||
|
|
||
|
|
||
| def is_leak_sensor_state_available(device: YoLinkDevice, data: dict) -> bool: | ||
| """Check leak sensor state availability.""" | ||
| if device.device_type == ATTR_DEVICE_MULTI_CAPS_LEAK_SENSOR: | ||
| if ( | ||
| (alarms := data.get("alarm")) is not None | ||
| and isinstance(alarms, list) | ||
| and "Alert.DetectorError" in alarms | ||
| ): | ||
| return False | ||
| if (alarms := data.get("alarmState")) is not None and alarms.get( | ||
| "detectorError" | ||
| ) is True: | ||
| return False | ||
| return True |
There was a problem hiding this comment.
Would it make sense to maybe split out the entity description into 2? As in, now we try to reuse the same entity description, but we have to mingle all this logic into it for it to work
There was a problem hiding this comment.
For different models of device of the same type, using the same entity description seems more reasonable. The data differences between models are distinguished within the parse_data_leak_sensor_state and is_leak_sensor_state_available functions.
Proposed change
Add support for YS7914
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: