-
-
Notifications
You must be signed in to change notification settings - Fork 37.4k
Add indevolt binary sensor platform #169375
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
Merged
abmantis
merged 18 commits into
home-assistant:dev
from
Xirt:add-indevolt-binary-sensor-platform
Apr 29, 2026
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d2c6c38
Add binary sensor platform to Indevolt integration
Xirt c6138fa
Updated to use API library 1.6.0
Xirt 8bd8288
Bump indevolt-api to 1.6.3
Xirt f1cb669
Merge remote-tracking branch 'origin/dev' into add-indevolt-binary-se…
Xirt 10f5279
Merge remote-tracking branch 'upstream/dev' into add-indevolt-binary-…
Xirt 68c253a
Bump indevolt-api to 1.6.4 and add binary sensor platform
Xirt 502d1b3
Update binary sensor snapshots for upstream entity registry format ch…
Xirt a474afc
Remove HEAT device class from gen 1 heating binary sensor
Xirt 9515d7d
Update tests/components/indevolt/test_binary_sensor.py
Xirt 7c2c833
Implement Copilot feedback in tests
Xirt d848cac
Update tests/components/indevolt/test_binary_sensor.py
Xirt 7650f00
Various improvements to tests
Xirt 23cb547
Improve test coverage via fixtures / snapshot updates
Xirt ca36205
Merge branch 'dev' into add-indevolt-binary-sensor-platform
Xirt 4bc1a1d
Incorporate copilot feedback
Xirt d0d002e
Process review feedback
Xirt 8cffb87
Use tuple instead of list for generation
Xirt 50b3a55
Optimize excluded_keys logic
Xirt 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
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,154 @@ | ||
| """Binary sensor platform for Indevolt integration.""" | ||
|
|
||
| from dataclasses import dataclass | ||
| from typing import Final | ||
|
|
||
| from indevolt_api import IndevoltBattery, IndevoltGrid, IndevoltSystem | ||
|
Xirt marked this conversation as resolved.
|
||
|
|
||
| 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 IndevoltConfigEntry | ||
| from .coordinator import IndevoltCoordinator | ||
| from .entity import IndevoltEntity | ||
|
|
||
| PARALLEL_UPDATES = 0 | ||
|
|
||
|
|
||
| @dataclass(frozen=True, kw_only=True) | ||
| class IndevoltBinarySensorEntityDescription(BinarySensorEntityDescription): | ||
| """Custom entity description class for Indevolt binary sensors.""" | ||
|
|
||
| on_value: int = 1 | ||
| off_value: int = 0 | ||
| generation: tuple[int, ...] = (1, 2) | ||
|
|
||
|
|
||
| BINARY_SENSORS: Final = ( | ||
| # Electricity Meter Status | ||
| IndevoltBinarySensorEntityDescription( | ||
| key=IndevoltGrid.METER_CONNECTED, | ||
| translation_key="meter_connected", | ||
| on_value=1000, | ||
| off_value=1001, | ||
| device_class=BinarySensorDeviceClass.CONNECTIVITY, | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| ), | ||
| # Electric Heating States | ||
| IndevoltBinarySensorEntityDescription( | ||
| key=IndevoltSystem.HEATING_STATE, | ||
| generation=(1,), | ||
| translation_key="electric_heating_state", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| ), | ||
|
Xirt marked this conversation as resolved.
|
||
| IndevoltBinarySensorEntityDescription( | ||
| key=IndevoltBattery.MAIN_HEATING_STATE, | ||
| generation=(2,), | ||
| translation_key="main_electric_heating_state", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| ), | ||
|
Xirt marked this conversation as resolved.
|
||
| IndevoltBinarySensorEntityDescription( | ||
| key=IndevoltBattery.PACK_1_HEATING_STATE, | ||
| generation=(2,), | ||
| translation_key="battery_pack_1_electric_heating_state", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| ), | ||
| IndevoltBinarySensorEntityDescription( | ||
| key=IndevoltBattery.PACK_2_HEATING_STATE, | ||
| generation=(2,), | ||
| translation_key="battery_pack_2_electric_heating_state", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| ), | ||
| IndevoltBinarySensorEntityDescription( | ||
| key=IndevoltBattery.PACK_3_HEATING_STATE, | ||
| generation=(2,), | ||
| translation_key="battery_pack_3_electric_heating_state", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| ), | ||
| IndevoltBinarySensorEntityDescription( | ||
| key=IndevoltBattery.PACK_4_HEATING_STATE, | ||
| generation=(2,), | ||
| translation_key="battery_pack_4_electric_heating_state", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| ), | ||
| IndevoltBinarySensorEntityDescription( | ||
| key=IndevoltBattery.PACK_5_HEATING_STATE, | ||
| generation=(2,), | ||
| translation_key="battery_pack_5_electric_heating_state", | ||
| entity_category=EntityCategory.DIAGNOSTIC, | ||
| entity_registry_enabled_default=False, | ||
| ), | ||
| ) | ||
|
|
||
| # Sensor per battery pack: (serial_number_key, heating_state_key) | ||
| BATTERY_PACK_SENSOR_KEYS = [ | ||
| (IndevoltBattery.PACK_1_SERIAL_NUMBER, IndevoltBattery.PACK_1_HEATING_STATE), | ||
| (IndevoltBattery.PACK_2_SERIAL_NUMBER, IndevoltBattery.PACK_2_HEATING_STATE), | ||
| (IndevoltBattery.PACK_3_SERIAL_NUMBER, IndevoltBattery.PACK_3_HEATING_STATE), | ||
| (IndevoltBattery.PACK_4_SERIAL_NUMBER, IndevoltBattery.PACK_4_HEATING_STATE), | ||
| (IndevoltBattery.PACK_5_SERIAL_NUMBER, IndevoltBattery.PACK_5_HEATING_STATE), | ||
| ] | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
| hass: HomeAssistant, | ||
| entry: IndevoltConfigEntry, | ||
| async_add_entities: AddConfigEntryEntitiesCallback, | ||
| ) -> None: | ||
| """Set up the binary sensor platform for Indevolt.""" | ||
| coordinator = entry.runtime_data | ||
| device_gen = coordinator.generation | ||
|
|
||
| excluded_keys: set[str] = set() | ||
| for sn_key, heating_key in BATTERY_PACK_SENSOR_KEYS: | ||
| if not coordinator.data.get(sn_key): | ||
| excluded_keys.add(heating_key) | ||
|
|
||
| async_add_entities( | ||
| IndevoltBinarySensorEntity(coordinator, description) | ||
| for description in BINARY_SENSORS | ||
| if device_gen in description.generation and description.key not in excluded_keys | ||
| ) | ||
|
Xirt marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class IndevoltBinarySensorEntity(IndevoltEntity, BinarySensorEntity): | ||
| """Represents a binary sensor entity for Indevolt devices.""" | ||
|
|
||
| entity_description: IndevoltBinarySensorEntityDescription | ||
|
|
||
| def __init__( | ||
| self, | ||
| coordinator: IndevoltCoordinator, | ||
| description: IndevoltBinarySensorEntityDescription, | ||
| ) -> None: | ||
| """Initialize the Indevolt binary sensor entity.""" | ||
| super().__init__(coordinator) | ||
|
|
||
| self.entity_description = description | ||
| self._attr_unique_id = f"{self.serial_number}_{description.key}" | ||
|
|
||
| @property | ||
| def is_on(self) -> bool | None: | ||
| """Return on/active state of the binary sensor.""" | ||
| raw_value = self.coordinator.data.get(self.entity_description.key) | ||
|
|
||
| if raw_value == self.entity_description.on_value: | ||
| return True | ||
|
|
||
| if raw_value == self.entity_description.off_value: | ||
| return False | ||
|
|
||
| return None | ||
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
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 |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ | |
| "6005": 0, | ||
| "6006": 277.16, | ||
| "6007": 256.39, | ||
| "7120": 1001, | ||
| "7120": 1000, | ||
| "7121": 1, | ||
| "21028": 0 | ||
| } | ||
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.