Skip to content
Open
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
8 changes: 5 additions & 3 deletions custom_components/bemfa/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"homekit": {},
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/larry-wong/bemfa/issues",
"requirements": ["paho-mqtt==1.6.1"],
"requirements": [
"paho-mqtt==2.1.0"
],
"ssdp": [],
"version": "1.4.0",
"version": "1.4.2",
"zeroconf": []
}
}
2 changes: 1 addition & 1 deletion custom_components/bemfa/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
self._hass = hass

# Init MQTT connection
self._mqttc = mqtt.Client(uid, mqtt.MQTTv311)
self._mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION1, uid, mqtt.MQTTv311)

self._topic_to_sync: dict[str, Sync] = {}

Expand Down
27 changes: 26 additions & 1 deletion custom_components/bemfa/sync_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
from typing import Any
import voluptuous as vol
from collections.abc import Iterable

from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN, SensorDeviceClass
from homeassistant.const import ATTR_DEVICE_CLASS
Expand All @@ -14,7 +15,8 @@
SelectSelectorConfig,
SelectSelectorMode,
)
from homeassistant.helpers.template import area_entities
from homeassistant.helpers import entity_registry
from homeassistant.helpers import device_registry
from .utils import has_key
from .const import (
OPTIONS_CO2,
Expand All @@ -29,6 +31,29 @@
_LOGGING = logging.getLogger(__name__)


def area_entities(hass: HomeAssistant, area_id: str) -> Iterable[str]:
"""Return entities for a given area ID or name."""
if area_id is None:
return []
ent_reg = entity_registry.async_get(hass)
entity_ids = [
entry.entity_id
for entry in entity_registry.async_entries_for_area(ent_reg, area_id)
]
dev_reg = device_registry.async_get(hass)
# We also need to add entities tied to a device in the area that don't themselves
# have an area specified since they inherit the area from the device.
entity_ids.extend(
[
entity.entity_id
for device in device_registry.async_entries_for_area(dev_reg, area_id)
for entity in entity_registry.async_entries_for_device(ent_reg, device.id)
if entity.area_id is None
]
)
return entity_ids


@SYNC_TYPES.register("sensor")
class Sensor(Sync):
"""Sync a hass area to bemfa sensor device."""
Expand Down