-
-
Notifications
You must be signed in to change notification settings - Fork 37.6k
Add binary_sensor platform to Vistapool #172234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fdebrus
wants to merge
23
commits into
home-assistant:dev
Choose a base branch
from
fdebrus:vistapool-binary-sensor
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,450
−5
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a96b335
Add binary_sensor platform to Vistapool
claude c43e73d
Vistapool: also require hasHidro for the hidro_fl2 binary sensor
claude 89f223c
Vistapool: return None from acid_tank when no tank data is available
claude 54839b1
Vistapool: use STATE_ON / STATE_OFF / STATE_UNKNOWN in binary_sensor …
claude 24ee9c3
Vistapool: align binary_sensor description keys with entity name slugs
claude 234bfaf
Vistapool: cover io_module disabled-by-default in binary_sensor tests
claude 037ee6e
Vistapool: rename acid_tank binary sensor to dosing_tank
claude 59da410
Vistapool: restore ph_pump_alarm naming on the PROBLEM-class entity
claude 1aeffa8
Vistapool: cover every diagnostic module entity as disabled-by-default
claude 628e548
Vistapool: clarify why module diagnostic entities exist regardless of…
claude 6ddaa78
Vistapool: use snapshot_platform for the binary_sensor default-fixtur…
claude 6bd904a
Vistapool: fold all-modules-enabled case into the parametrized snapsh…
claude 6f03880
Vistapool: drop CONNECTIVITY device class from module-presence binary…
claude a040ed4
Vistapool: add binary_sensor snapshot
claude 2fcc69a
Vistapool: coerce numeric-as-string API values before bool conversion
claude 7cc58c8
Vistapool: coerce has* flags in entity-creation gates
claude a29fdd4
Vistapool: pin PLATFORMS to binary_sensor across the test module
claude 2293d94
Vistapool: rewrite dosing_tank None filter as an explicit loop
claude ebf64e6
Vistapool: fix codespell finding (unparseable -> unparsable)
claude 11702fd
Vistapool: switch to async_load_json_object_fixture in tests
claude c5f1308
Vistapool: simplify binary_sensor coercion per joostlek's review
claude 019d2f9
Merge remote-tracking branch 'upstream/dev' into vistapool-binary-sensor
claude f4429fc
Vistapool: deepcopy _LED_DATA in button tests to prevent cross-test m…
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,255 @@ | ||
| """Vistapool Binary Sensor entities.""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Any | ||
|
|
||
| from homeassistant.components.binary_sensor import ( | ||
| BinarySensorDeviceClass, | ||
| BinarySensorEntity, | ||
| BinarySensorEntityDescription, | ||
| ) | ||
| from homeassistant.const import EntityCategory | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback | ||
|
|
||
| from . import VistapoolConfigEntry | ||
| from .const import ( | ||
| PATH_HASCD, | ||
| PATH_HASCL, | ||
| PATH_HASHIDRO, | ||
| PATH_HASIO, | ||
| PATH_HASPH, | ||
| PATH_HASRX, | ||
| ) | ||
| from .coordinator import VistapoolDataUpdateCoordinator | ||
| from .entity import VistapoolEntity | ||
|
|
||
| PARALLEL_UPDATES = 1 | ||
|
|
||
| TANK_MODULE_PATHS = ( | ||
| "modules.ph.tank", | ||
| "modules.rx.tank", | ||
| "modules.cl.tank", | ||
| "modules.cd.tank", | ||
| ) | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class VistapoolBinarySensorEntityDescription(BinarySensorEntityDescription): | ||
| """Describes a Vistapool binary sensor entity.""" | ||
|
|
||
| value_path: str | ||
| exists_path: str | tuple[str, ...] | None = None | ||
|
|
||
|
|
||
| BINARY_SENSOR_DESCRIPTIONS: tuple[VistapoolBinarySensorEntityDescription, ...] = ( | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="filtration", | ||
| translation_key="filtration", | ||
| device_class=BinarySensorDeviceClass.RUNNING, | ||
| value_path="filtration.status", | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="backwash", | ||
| translation_key="backwash", | ||
| device_class=BinarySensorDeviceClass.RUNNING, | ||
| value_path="backwash.status", | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="heating", | ||
| translation_key="heating", | ||
| device_class=BinarySensorDeviceClass.RUNNING, | ||
| value_path="relays.filtration.heating.status", | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="hidro_flow", | ||
| translation_key="hidro_flow", | ||
| device_class=BinarySensorDeviceClass.PROBLEM, | ||
| value_path="hidro.fl1", | ||
| exists_path=PATH_HASHIDRO, | ||
| ), | ||
|
fdebrus marked this conversation as resolved.
|
||
| VistapoolBinarySensorEntityDescription( | ||
| key="hidro_cover_reduction", | ||
| translation_key="hidro_cover_reduction", | ||
| device_class=BinarySensorDeviceClass.RUNNING, | ||
| value_path="hidro.cover", | ||
| exists_path=PATH_HASHIDRO, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="hidro_fl2", | ||
| translation_key="hidro_fl2", | ||
| device_class=BinarySensorDeviceClass.PROBLEM, | ||
| value_path="hidro.fl2", | ||
| exists_path=(PATH_HASHIDRO, PATH_HASCL), | ||
| ), | ||
|
fdebrus marked this conversation as resolved.
|
||
| VistapoolBinarySensorEntityDescription( | ||
| key="chlorine_pump", | ||
| translation_key="chlorine_pump", | ||
| device_class=BinarySensorDeviceClass.RUNNING, | ||
| value_path="modules.cl.pump_status", | ||
| exists_path=PATH_HASCL, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="redox_pump", | ||
| translation_key="redox_pump", | ||
| device_class=BinarySensorDeviceClass.RUNNING, | ||
| value_path="modules.rx.pump_status", | ||
| exists_path=PATH_HASRX, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="ph_pump_alarm", | ||
| translation_key="ph_pump_alarm", | ||
| device_class=BinarySensorDeviceClass.PROBLEM, | ||
| value_path="modules.ph.al3", | ||
| exists_path=PATH_HASPH, | ||
| ), | ||
|
fdebrus marked this conversation as resolved.
fdebrus marked this conversation as resolved.
|
||
| VistapoolBinarySensorEntityDescription( | ||
| key="ph_acid_pump", | ||
| translation_key="ph_acid_pump", | ||
| device_class=BinarySensorDeviceClass.RUNNING, | ||
| value_path="modules.ph.pump_high_on", | ||
| exists_path=PATH_HASPH, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="ph_base_pump", | ||
| translation_key="ph_base_pump", | ||
| device_class=BinarySensorDeviceClass.RUNNING, | ||
| value_path="modules.ph.pump_low_on", | ||
| exists_path=PATH_HASPH, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="conductivity_module", | ||
| translation_key="conductivity_module", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| value_path=PATH_HASCD, | ||
|
fdebrus marked this conversation as resolved.
|
||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="chlorine_module", | ||
| translation_key="chlorine_module", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| value_path=PATH_HASCL, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="redox_module", | ||
| translation_key="redox_module", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| value_path=PATH_HASRX, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="ph_module", | ||
| translation_key="ph_module", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| value_path=PATH_HASPH, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="io_module", | ||
| translation_key="io_module", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| value_path=PATH_HASIO, | ||
| ), | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="hidro_module", | ||
| translation_key="hidro_module", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| value_path=PATH_HASHIDRO, | ||
| ), | ||
|
fdebrus marked this conversation as resolved.
|
||
| ) | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| entry: VistapoolConfigEntry, | ||
| async_add_entities: AddConfigEntryEntitiesCallback, | ||
| ) -> None: | ||
| """Set up Vistapool binary sensors for every pool on the account.""" | ||
| entities: list[BinarySensorEntity] = [] | ||
|
|
||
| for coordinator in entry.runtime_data.coordinators.values(): | ||
| for description in BINARY_SENSOR_DESCRIPTIONS: | ||
| if description.exists_path is not None: | ||
| required = ( | ||
| (description.exists_path,) | ||
| if isinstance(description.exists_path, str) | ||
| else description.exists_path | ||
| ) | ||
| if not all(coordinator.get_value(path) for path in required): | ||
| continue | ||
|
fdebrus marked this conversation as resolved.
fdebrus marked this conversation as resolved.
|
||
| entities.append(VistapoolBinarySensor(coordinator, description)) | ||
|
|
||
| if coordinator.get_value(PATH_HASHIDRO): | ||
| is_electrolysis = coordinator.get_value("hidro.is_electrolysis") | ||
| entities.append( | ||
| VistapoolBinarySensor( | ||
| coordinator, | ||
| VistapoolBinarySensorEntityDescription( | ||
| key="electrolysis_low" if is_electrolysis else "hydrolysis_low", | ||
| translation_key=( | ||
| "electrolysis_low" if is_electrolysis else "hydrolysis_low" | ||
| ), | ||
| device_class=BinarySensorDeviceClass.PROBLEM, | ||
| value_path="hidro.low", | ||
| ), | ||
| ) | ||
| ) | ||
|
|
||
| if any( | ||
| coordinator.get_value(path) | ||
| for path in (PATH_HASCD, PATH_HASCL, PATH_HASPH, PATH_HASRX) | ||
| ): | ||
|
fdebrus marked this conversation as resolved.
|
||
| entities.append(VistapoolDosingTankBinarySensor(coordinator)) | ||
|
fdebrus marked this conversation as resolved.
|
||
|
|
||
| async_add_entities(entities) | ||
|
|
||
|
|
||
| class VistapoolBinarySensor(VistapoolEntity, BinarySensorEntity): | ||
| """Generic Vistapool binary sensor driven by an entity description.""" | ||
|
|
||
| entity_description: VistapoolBinarySensorEntityDescription | ||
|
|
||
| def __init__( | ||
| self, | ||
| coordinator: VistapoolDataUpdateCoordinator, | ||
| description: VistapoolBinarySensorEntityDescription, | ||
| ) -> None: | ||
| """Initialize the binary sensor.""" | ||
| super().__init__(coordinator) | ||
| self.entity_description = description | ||
| self._attr_unique_id = self.build_unique_id(description.key) | ||
|
|
||
| @property | ||
| def is_on(self) -> bool | None: | ||
| """Return true if the binary sensor is on.""" | ||
| value = self.coordinator.get_value(self.entity_description.value_path) | ||
| if value is None: | ||
| return None | ||
| return value in (True, "1") | ||
|
fdebrus marked this conversation as resolved.
fdebrus marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class VistapoolDosingTankBinarySensor(VistapoolEntity, BinarySensorEntity): | ||
| """Dosing-tank low-level sensor: on if any installed dosing module reports low.""" | ||
|
|
||
| _attr_device_class = BinarySensorDeviceClass.PROBLEM | ||
| _attr_translation_key = "dosing_tank" | ||
|
|
||
| def __init__(self, coordinator: VistapoolDataUpdateCoordinator) -> None: | ||
| """Initialize the dosing-tank binary sensor.""" | ||
| super().__init__(coordinator) | ||
| self._attr_unique_id = self.build_unique_id("dosing_tank") | ||
|
|
||
| @property | ||
| def is_on(self) -> bool | None: | ||
| """Return true if any tank is low, or None if no tank data is available.""" | ||
|
fdebrus marked this conversation as resolved.
|
||
| values: list[Any] = [] | ||
| for path in TANK_MODULE_PATHS: | ||
| value = self.coordinator.get_value(path) | ||
| if value is not None: | ||
| values.append(value) | ||
| if not values: | ||
| return None | ||
| return any(value in (True, "1") for value in values) | ||
|
fdebrus marked this conversation as resolved.
fdebrus marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.