Skip to content

Commit

Permalink
Bump hahomematic to 2024.10.15 (#749)
Browse files Browse the repository at this point in the history
* Bump hahomematic to 2024.10.15

* Follow backend
  • Loading branch information
SukramJ authored Oct 27, 2024
1 parent 8664a45 commit 71a6743
Show file tree
Hide file tree
Showing 33 changed files with 845 additions and 791 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Version 1.69.0 (2024-10-26)
# Version 1.69.0 (2024-10-27)
- Bump hahomematic to 2024.10.15
- Rename entity to data point to better distinguish from HA
- Add missing action icons
- Follow backend changes

# Version 1.68.1 (2024-10-26)
- Bump hahomematic to 2024.10.14
Expand Down
48 changes: 25 additions & 23 deletions custom_components/homematicip_local/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import logging

from hahomematic.const import HmPlatform
from hahomematic.platforms.generic import HmBinarySensor
from hahomematic.platforms.hub import HmSysvarBinarySensor
from hahomematic.const import DataPointCategory
from hahomematic.model.generic import DpBinarySensor
from hahomematic.model.hub import SysvarDpBinarySensor

from homeassistant.components.binary_sensor import BinarySensorEntity
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN
Expand All @@ -15,7 +15,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomematicConfigEntry
from .control_unit import ControlUnit, signal_new_hm_entity
from .control_unit import ControlUnit, signal_new_data_point
from .generic_entity import HaHomematicGenericRestoreEntity, HaHomematicGenericSysvarEntity

_LOGGER = logging.getLogger(__name__)
Expand All @@ -30,73 +30,75 @@ async def async_setup_entry(
control_unit: ControlUnit = entry.runtime_data

@callback
def async_add_binary_sensor(hm_entities: tuple[HmBinarySensor, ...]) -> None:
def async_add_binary_sensor(data_points: tuple[DpBinarySensor, ...]) -> None:
"""Add binary_sensor from Homematic(IP) Local."""
_LOGGER.debug("ASYNC_ADD_BINARY_SENSOR: Adding %i entities", len(hm_entities))
_LOGGER.debug("ASYNC_ADD_BINARY_SENSOR: Adding %i data points", len(data_points))
if entities := [
HaHomematicBinarySensor(control_unit=control_unit, hm_entity=hm_entity)
for hm_entity in hm_entities
HaHomematicBinarySensor(control_unit=control_unit, data_point=data_point)
for data_point in data_points
]:
async_add_entities(entities)

@callback
def async_add_hub_binary_sensor(hm_entities: tuple[HmSysvarBinarySensor, ...]) -> None:
def async_add_hub_binary_sensor(data_points: tuple[SysvarDpBinarySensor, ...]) -> None:
"""Add sysvar binary sensor from Homematic(IP) Local."""
_LOGGER.debug("ASYNC_ADD_HUB_BINARY_SENSOR: Adding %i entities", len(hm_entities))
_LOGGER.debug("ASYNC_ADD_HUB_BINARY_SENSOR: Adding %i data points", len(data_points))
if entities := [
HaHomematicSysvarBinarySensor(control_unit=control_unit, hm_sysvar_entity=hm_entity)
for hm_entity in hm_entities
HaHomematicSysvarBinarySensor(control_unit=control_unit, data_point=data_point)
for data_point in data_points
]:
async_add_entities(entities)

entry.async_on_unload(
func=async_dispatcher_connect(
hass=hass,
signal=signal_new_hm_entity(
entry_id=entry.entry_id, platform=HmPlatform.BINARY_SENSOR
signal=signal_new_data_point(
entry_id=entry.entry_id, platform=DataPointCategory.BINARY_SENSOR
),
target=async_add_binary_sensor,
)
)
entry.async_on_unload(
func=async_dispatcher_connect(
hass=hass,
signal=signal_new_hm_entity(entry.entry_id, HmPlatform.HUB_BINARY_SENSOR),
signal=signal_new_data_point(entry.entry_id, DataPointCategory.HUB_BINARY_SENSOR),
target=async_add_hub_binary_sensor,
)
)

async_add_binary_sensor(hm_entities=control_unit.get_new_entities(entity_type=HmBinarySensor))
async_add_binary_sensor(
data_points=control_unit.get_new_data_points(data_point_type=DpBinarySensor)
)

async_add_hub_binary_sensor(
hm_entities=control_unit.get_new_hub_entities(entity_type=HmSysvarBinarySensor)
data_points=control_unit.get_new_hub_data_points(data_point_type=SysvarDpBinarySensor)
)


class HaHomematicBinarySensor(HaHomematicGenericRestoreEntity[HmBinarySensor], BinarySensorEntity):
class HaHomematicBinarySensor(HaHomematicGenericRestoreEntity[DpBinarySensor], BinarySensorEntity):
"""Representation of the Homematic(IP) Local binary sensor."""

@property
def is_on(self) -> bool | None:
"""Return true if sensor is active."""
if self._hm_entity.is_valid:
return self._hm_entity.value
if self._data_point.is_valid:
return self._data_point.value
if (
self.is_restored
and self._restored_state
and (restored_state := self._restored_state.state)
not in (STATE_UNKNOWN, STATE_UNAVAILABLE)
):
return restored_state == STATE_ON
return self._hm_entity.default # type: ignore[no-any-return]
return self._data_point.default # type: ignore[no-any-return]


class HaHomematicSysvarBinarySensor(
HaHomematicGenericSysvarEntity[HmSysvarBinarySensor], BinarySensorEntity
HaHomematicGenericSysvarEntity[SysvarDpBinarySensor], BinarySensorEntity
):
"""Representation of the HomematicIP hub binary_sensor entity."""

@property
def is_on(self) -> bool | None:
"""Return the native value of the entity."""
return bool(self._hm_hub_entity.value)
return bool(self._data_point.value)
50 changes: 27 additions & 23 deletions custom_components/homematicip_local/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

import logging

from hahomematic.const import HmPlatform
from hahomematic.platforms.generic import HmButton
from hahomematic.platforms.hub import HmProgramButton
from hahomematic.const import DataPointCategory
from hahomematic.model.generic import DpButton
from hahomematic.model.hub import ProgramDpButton

from homeassistant.components.button import ButtonEntity
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import HomematicConfigEntry
from .control_unit import ControlUnit, signal_new_hm_entity
from .control_unit import ControlUnit, signal_new_data_point
from .generic_entity import ATTR_NAME, HaHomematicGenericEntity, HaHomematicGenericHubEntity

_LOGGER = logging.getLogger(__name__)
Expand All @@ -29,59 +29,63 @@ async def async_setup_entry(
control_unit: ControlUnit = entry.runtime_data

@callback
def async_add_button(hm_entities: tuple[HmButton, ...]) -> None:
def async_add_button(data_points: tuple[DpButton, ...]) -> None:
"""Add button from Homematic(IP) Local."""
_LOGGER.debug("ASYNC_ADD_BUTTON: Adding %i entities", len(hm_entities))
_LOGGER.debug("ASYNC_ADD_BUTTON: Adding %i data points", len(data_points))

if entities := [
HaHomematicButton(
control_unit=control_unit,
hm_entity=hm_entity,
data_point=data_point,
)
for hm_entity in hm_entities
for data_point in data_points
]:
async_add_entities(entities)

@callback
def async_add_program_button(hm_entities: tuple[HmProgramButton, ...]) -> None:
def async_add_program_button(data_points: tuple[ProgramDpButton, ...]) -> None:
"""Add program button from Homematic(IP) Local."""
_LOGGER.debug("ASYNC_ADD_PROGRAM_BUTTON: Adding %i entities", len(hm_entities))
_LOGGER.debug("ASYNC_ADD_PROGRAM_BUTTON: Adding %i data points", len(data_points))

if entities := [
HaHomematicProgramButton(control_unit=control_unit, hm_program_button=hm_entity)
for hm_entity in hm_entities
HaHomematicProgramButton(control_unit=control_unit, data_point=data_point)
for data_point in data_points
]:
async_add_entities(entities)

entry.async_on_unload(
func=async_dispatcher_connect(
hass=hass,
signal=signal_new_hm_entity(entry_id=entry.entry_id, platform=HmPlatform.BUTTON),
signal=signal_new_data_point(
entry_id=entry.entry_id, platform=DataPointCategory.BUTTON
),
target=async_add_button,
)
)

entry.async_on_unload(
func=async_dispatcher_connect(
hass=hass,
signal=signal_new_hm_entity(entry_id=entry.entry_id, platform=HmPlatform.HUB_BUTTON),
signal=signal_new_data_point(
entry_id=entry.entry_id, platform=DataPointCategory.HUB_BUTTON
),
target=async_add_program_button,
)
)

async_add_button(hm_entities=control_unit.get_new_entities(entity_type=HmButton))
async_add_button(data_points=control_unit.get_new_data_points(data_point_type=DpButton))

async_add_program_button(
hm_entities=control_unit.get_new_hub_entities(entity_type=HmProgramButton)
data_points=control_unit.get_new_hub_data_points(data_point_type=ProgramDpButton)
)


class HaHomematicButton(HaHomematicGenericEntity[HmButton], ButtonEntity):
class HaHomematicButton(HaHomematicGenericEntity[DpButton], ButtonEntity):
"""Representation of the Homematic(IP) Local button."""

async def async_press(self) -> None:
"""Execute a button press."""
await self._hm_entity.press()
await self._data_point.press()


class HaHomematicProgramButton(HaHomematicGenericHubEntity, ButtonEntity):
Expand All @@ -90,16 +94,16 @@ class HaHomematicProgramButton(HaHomematicGenericHubEntity, ButtonEntity):
def __init__(
self,
control_unit: ControlUnit,
hm_program_button: HmProgramButton,
data_point: ProgramDpButton,
) -> None:
"""Initialize the button entity."""
super().__init__(
control_unit=control_unit,
hm_hub_entity=hm_program_button,
data_point=data_point,
)
self._hm_hub_entity: HmProgramButton = hm_program_button
self._attr_extra_state_attributes = {ATTR_NAME: self._hm_hub_entity.ccu_program_name}
self._data_point: ProgramDpButton = data_point
self._attr_extra_state_attributes = {ATTR_NAME: self._data_point.ccu_program_name}

async def async_press(self) -> None:
"""Execute a button press."""
await self._hm_hub_entity.press()
await self._data_point.press()
Loading

0 comments on commit 71a6743

Please sign in to comment.