Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions homeassistant/components/indevolt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .services import async_setup_services

PLATFORMS: list[Platform] = [
Platform.BINARY_SENSOR,
Platform.BUTTON,
Comment thread
Xirt marked this conversation as resolved.
Platform.NUMBER,
Platform.SELECT,
Expand Down
154 changes: 154 additions & 0 deletions homeassistant/components/indevolt/binary_sensor.py
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
Comment thread
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,
),
Comment thread
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,
),
Comment thread
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
)
Comment thread
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
9 changes: 9 additions & 0 deletions homeassistant/components/indevolt/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
IndevoltSolar.DC_INPUT_POWER_4,
IndevoltConfig.READ_DISCHARGE_LIMIT,
IndevoltGrid.METER_POWER_GEN1,
IndevoltGrid.METER_CONNECTED,
IndevoltSolar.CUMULATIVE_PRODUCTION,
IndevoltSystem.HEATING_STATE,
],
2: [
IndevoltSystem.OPERATING_MODE,
Expand Down Expand Up @@ -112,6 +114,13 @@
IndevoltConfig.READ_INVERTER_INPUT_LIMIT,
IndevoltConfig.READ_FEEDIN_POWER_LIMIT,
IndevoltConfig.READ_DISCHARGE_LIMIT,
IndevoltBattery.MAIN_HEATING_STATE,
IndevoltBattery.PACK_1_HEATING_STATE,
IndevoltBattery.PACK_2_HEATING_STATE,
IndevoltBattery.PACK_3_HEATING_STATE,
IndevoltBattery.PACK_4_HEATING_STATE,
IndevoltBattery.PACK_5_HEATING_STATE,
IndevoltGrid.METER_CONNECTED,
IndevoltSolar.CUMULATIVE_PRODUCTION,
],
}
26 changes: 26 additions & 0 deletions homeassistant/components/indevolt/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,32 @@
}
},
"entity": {
"binary_sensor": {
"battery_pack_1_electric_heating_state": {
"name": "Battery pack 1 electric heating"
},
"battery_pack_2_electric_heating_state": {
"name": "Battery pack 2 electric heating"
},
"battery_pack_3_electric_heating_state": {
"name": "Battery pack 3 electric heating"
},
"battery_pack_4_electric_heating_state": {
"name": "Battery pack 4 electric heating"
},
"battery_pack_5_electric_heating_state": {
"name": "Battery pack 5 electric heating"
},
"electric_heating_state": {
"name": "Electric heating"
},
"main_electric_heating_state": {
"name": "Main electric heating"
},
"meter_connected": {
"name": "Meter connected"
}
},
"button": {
"stop": {
"name": "Enable standby mode"
Expand Down
3 changes: 2 additions & 1 deletion tests/components/indevolt/fixtures/gen_1.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"6005": 0,
"6006": 277.16,
"6007": 256.39,
"7120": 1001,
"7120": 1000,
"7121": 1,
"21028": 0
}
6 changes: 6 additions & 0 deletions tests/components/indevolt/fixtures/gen_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
"6006": 380.58,
"6007": 338.07,
"7120": 1001,
"9079": 1,
"9096": 1,
"9112": 0,
"9128": 1,
"9144": 0,
"9279": 1,
"11016": 0,
"2600": 1200,
"2612": 50.0,
Expand Down
Loading
Loading