Skip to content

Commit

Permalink
multiple Fixes (#68)
Browse files Browse the repository at this point in the history
* Add Github Basics

* Add button entity_description

* Fix unload issue

* De-Init Hub

* Fix device description_strategy
  • Loading branch information
SukramJ authored Dec 31, 2021
1 parent 7bc2211 commit 0e559bb
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 10 deletions.
7 changes: 7 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Contributing to hahomematic's custom_component

If there is anything you want to see in hahomematic's custom_component (features, bugfixes etc.), you can fork this repository, make your changes and then create a pull request (against the devel-branch). Just like with most of the other repositories here.

Please restrict your changes to the actual code within the custom_components/hahm-folder. The repository-maintainers are keeping track of changes and will updated the changelog and setup.py.

If you can't do it yourself, feel free to create an issue and we'll have a look at it.
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Version 0.10.0 (2021-12-31)
- Add Github Basics
- Add button entity_description
- Fix unload issue
- Fix device description_strategy

Version 0.9.2 (2021-12-30)
- Adopt async changes from hahomematic
- Bump hahomematic to 0.9.1:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/hahm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
"""Unload a config entry."""
control = hass.data[DOMAIN][config_entry.entry_id]
await control.async_stop()
control.central.clear_all()
await control.central.clear_all()
if unload_ok := await hass.config_entries.async_unload_platforms(
config_entry, HAHM_PLATFORMS
):
Expand Down
11 changes: 10 additions & 1 deletion custom_components/hahm/control_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
from __future__ import annotations

from collections.abc import Callable
from datetime import datetime, timedelta
import logging
from types import MappingProxyType
Expand Down Expand Up @@ -121,6 +122,8 @@ def _async_add_central_to_device_registry(self) -> None:
async def async_stop(self) -> None:
"""Stop the control unit."""
_LOGGER.debug("Stopping HAHM ControlUnit %s", self._data[ATTR_INSTANCE_NAME])
if self._hub:
self._hub.de_init()
self.central.stop_connection_checker()
for client in self.central.clients.values():
await client.proxy_de_init()
Expand Down Expand Up @@ -458,14 +461,20 @@ def __init__(
self._attr_name: str = self._control.central.instance_name
self.entity_id = f"{DOMAIN}.{slugify(self._attr_name.lower())}"
self._hm_hub.register_update_callback(self._async_update_hub)
self.remove_listener: Callable | None = None

async def async_init(self) -> None:
"""Init fetch scheduler."""
self.hass.helpers.event.async_track_time_interval(
self.remove_listener = self.hass.helpers.event.async_track_time_interval(
self._async_fetch_data, SCAN_INTERVAL
)
await self._async_fetch_data(now=datetime.now())

def de_init(self):
"""De_init the hub."""
if callback(self.remove_listener):
self.remove_listener()

@property
def available(self) -> bool:
"""Return if entity is available."""
Expand Down
29 changes: 24 additions & 5 deletions custom_components/hahm/entity_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,25 @@

_LOGGER = logging.getLogger(__name__)

_NUMBER_DESCRIPTIONS_BY_PARAM: dict[str, NumberEntityDescription] = {
"ACTIVE_PROFILE": NumberEntityDescription(
key="ACTIVE_PROFILE",
icon="mdi:hvac",

_BUTTON_DESCRIPTIONS_BY_PARAM: dict[str, ButtonEntityDescription] = {
"RESET_MOTION": ButtonEntityDescription(
key="RESET_MOTION",
icon="mdi:gesture-tap",
entity_registry_enabled_default=False,
),
"RESET_PRESENCE": ButtonEntityDescription(
key="RESET_PRESENCE",
icon="mdi:gesture-tap",
entity_registry_enabled_default=False,
),
}

_NUMBER_DESCRIPTIONS_BY_PARAM: dict[str, NumberEntityDescription] = {
"LEVEL": NumberEntityDescription(
key="LEVEL",
icon="mdi:radiator",
entity_registry_enabled_default=False,
),
}

Expand Down Expand Up @@ -447,6 +458,7 @@

_ENTITY_DESCRIPTION_PARAM: dict[HmPlatform, dict[str, Any]] = {
HmPlatform.BINARY_SENSOR: _BINARY_SENSOR_DESCRIPTIONS_BY_PARAM,
HmPlatform.BUTTON: _BUTTON_DESCRIPTIONS_BY_PARAM,
HmPlatform.NUMBER: _NUMBER_DESCRIPTIONS_BY_PARAM,
HmPlatform.SENSOR: _SENSOR_DESCRIPTIONS_BY_PARAM,
}
Expand Down Expand Up @@ -500,7 +512,14 @@ def get_entity_description(hm_entity: HmGenericEntity) -> EntityDescription | No
if platform_param_descriptions := _ENTITY_DESCRIPTION_PARAM.get(
hm_entity.platform
):
return platform_param_descriptions.get(hm_entity.parameter)
entity_description = platform_param_descriptions.get(hm_entity.parameter)


if entity_description:
return entity_description

if hasattr(hm_entity, "platform"):
return _DEFAULT_DESCRIPTION.get(hm_entity.platform, None)

elif isinstance(hm_entity, CustomEntity):
if platform_device_descriptions := _ENTITY_DESCRIPTION_DEVICE.get(
Expand Down
4 changes: 2 additions & 2 deletions custom_components/hahm/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"config_flow": true,
"documentation": "https://github.com/danielperna84/hahomematic",
"issue_tracker": "https://github.com/danielperna84/hahomematic/issues",
"requirements": ["hahomematic==0.9.1"],
"requirements": ["hahomematic==0.10.0"],
"requirements1": ["git+https://github.com/SukramJ/hahomematic.git@dev1#hahomematic"],
"ssdp": [],
"zeroconf": [],
"homekit": {},
"dependencies": [],
"codeowners": ["@danielperna84", "@SukramJ"],
"iot_class": "local_push",
"version": "0.9.2"
"version": "0.10.0"
}
2 changes: 1 addition & 1 deletion custom_components/hahm/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def _get_device(hass: HomeAssistant, device_id: str) -> HmDevice | None:
device_address = data[0]
interface_id = data[1]

if control_unit:= _get_cu_by_interface_id(hass=hass, interface_id=interface_id):
if control_unit := _get_cu_by_interface_id(hass=hass, interface_id=interface_id):
return control_unit.central.hm_devices.get(device_address)
return None

Expand Down

0 comments on commit 0e559bb

Please sign in to comment.