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
4 changes: 2 additions & 2 deletions custom_components/bemfa/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Final

from homeassistant.backports.enum import StrEnum
import enum

DOMAIN: Final = "bemfa"

Expand Down Expand Up @@ -33,7 +33,7 @@
OPTIONS_SWING_BOTH_VALUE: Final = "swing_both_value"

# #### MQTT ####
class TopicSuffix(StrEnum):
class TopicSuffix(enum.StrEnum):
"""Suffix for bemfa MQTT topic"""

LIGHT = "002"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/bemfa/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"homekit": {},
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/larry-wong/bemfa/issues",
"requirements": ["paho-mqtt==1.6.1"],
"requirements": ["paho-mqtt"],
"ssdp": [],
"version": "1.4.0",
"zeroconf": []
Expand Down
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(client_id=uid, protocol=mqtt.MQTTv311, callback_api_version=mqtt.CallbackAPIVersion.VERSION1)

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

Expand Down
16 changes: 8 additions & 8 deletions custom_components/bemfa/sync_light.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_BRIGHTNESS_PCT,
ATTR_COLOR_TEMP,
ATTR_MAX_MIREDS,
ATTR_MIN_MIREDS,
ATTR_COLOR_TEMP_KELVIN,
ATTR_MIN_COLOR_TEMP_KELVIN,
ATTR_MAX_COLOR_TEMP_KELVIN,
ATTR_RGB_COLOR,
ATTR_SUPPORTED_COLOR_MODES,
DOMAIN,
Expand Down Expand Up @@ -45,8 +45,8 @@ def _msg_generators(
lambda state, attributes: round(attributes[ATTR_BRIGHTNESS] / 2.55)
if has_key(attributes, ATTR_BRIGHTNESS)
else "",
lambda state, attributes: 1000000 // attributes[ATTR_COLOR_TEMP]
if has_key(attributes, ATTR_COLOR_TEMP)
lambda state, attributes: 1000000 // attributes[ATTR_COLOR_TEMP_KELVIN]
if has_key(attributes, ATTR_COLOR_TEMP_KELVIN)
else attributes[ATTR_RGB_COLOR][0] * 256 * 256
+ attributes[ATTR_RGB_COLOR][1] * 256
+ attributes[ATTR_RGB_COLOR][2]
Expand Down Expand Up @@ -75,9 +75,9 @@ def _msg_resolvers(
SERVICE_TURN_ON if msg[0] == MSG_ON else SERVICE_TURN_OFF,
{
ATTR_BRIGHTNESS_PCT: msg[1],
ATTR_COLOR_TEMP: min(
max(1000000 // msg[2], attributes[ATTR_MIN_MIREDS]),
attributes[ATTR_MAX_MIREDS],
ATTR_COLOR_TEMP_KELVIN: min(
max(1000000 // msg[2], attributes[ATTR_MAX_COLOR_TEMP_KELVIN]),
attributes[ATTR_MIN_COLOR_TEMP_KELVIN],
),
}
if len(msg) > 2
Expand Down
8 changes: 6 additions & 2 deletions custom_components/bemfa/sync_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
SelectSelectorConfig,
SelectSelectorMode,
)
from homeassistant.helpers.template import area_entities
from homeassistant.helpers import entity_registry as er
from .utils import has_key
from .const import (
OPTIONS_CO2,
Expand Down Expand Up @@ -57,7 +57,11 @@ def generate_details_schema(self) -> dict[str, Any]:
co2_sensors: dict[str, str] = {}

# filter entities in our area
a_entities = area_entities(self._hass, self._entity_id.split(".")[1])
area_id = self._entity_id.split(".")[1]
entity_reg = er.async_get(self._hass)
a_entities = {
entry.entity_id for entry in entity_reg.async_entries_for_area(area_id)
}

for state in self._hass.states.async_all(SENSOR_DOMAIN):
if state.entity_id not in a_entities:
Expand Down
13 changes: 6 additions & 7 deletions custom_components/bemfa/sync_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from collections.abc import Mapping, Callable
from typing import Any
from homeassistant.components.automation import DOMAIN as AUTOMATION_DOMAIN
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN, STATE_IDLE
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN, CameraState
from homeassistant.components.group import DOMAIN as GROUP_DOMAIN
from homeassistant.components.humidifier import DOMAIN as HUMIDIFIER_DOMAIN
from homeassistant.components.input_boolean import DOMAIN as INPUT_BOOLEAN_DOMAIN
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN, LockState
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN
Expand All @@ -20,7 +20,7 @@
SERVICE_RETURN_TO_BASE,
SERVICE_START,
SERVICE_STOP,
STATE_CLEANING,
VacuumActivity,
VacuumEntityFeature,
)
from homeassistant.const import (
Expand All @@ -29,7 +29,6 @@
SERVICE_TURN_ON,
SERVICE_UNLOCK,
SERVICE_LOCK,
STATE_LOCKED,
STATE_ON,
STATE_PLAYING,
)
Expand Down Expand Up @@ -120,7 +119,7 @@ def _supported_domain() -> str:
def _msg_generator(
self,
) -> Callable[[str, ReadOnlyDict[Mapping[str, Any]]], str | int]:
return lambda state, attributes: MSG_OFF if state == STATE_IDLE else MSG_ON
return lambda state, attributes: MSG_OFF if state == CameraState.IDLE else MSG_ON
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison with CameraState.IDLE will fail because state is a string but CameraState.IDLE is an enum. The enum needs to be converted to its string value for comparison.

Change to:

return lambda state, attributes: MSG_OFF if state == CameraState.IDLE.value else MSG_ON

or use:

return lambda state, attributes: MSG_OFF if state == str(CameraState.IDLE) else MSG_ON
Suggested change
return lambda state, attributes: MSG_OFF if state == CameraState.IDLE else MSG_ON
return lambda state, attributes: MSG_OFF if state == CameraState.IDLE.value else MSG_ON

Copilot uses AI. Check for mistakes.


@SYNC_TYPES.register("media_player")
Expand Down Expand Up @@ -148,7 +147,7 @@ def _supported_domain() -> str:
def _msg_generator(
self,
) -> Callable[[str, ReadOnlyDict[Mapping[str, Any]]], str | int]:
return lambda state, attributes: MSG_OFF if state == STATE_LOCKED else MSG_ON
return lambda state, attributes: MSG_OFF if state == LockState.LOCKED else MSG_ON
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison with LockState.LOCKED will fail because state is a string but LockState.LOCKED is an enum. The enum needs to be converted to its string value for comparison.

Change to:

return lambda state, attributes: MSG_OFF if state == LockState.LOCKED.value else MSG_ON

or use:

return lambda state, attributes: MSG_OFF if state == str(LockState.LOCKED) else MSG_ON
Suggested change
return lambda state, attributes: MSG_OFF if state == LockState.LOCKED else MSG_ON
return lambda state, attributes: MSG_OFF if state == LockState.LOCKED.value else MSG_ON

Copilot uses AI. Check for mistakes.

def _service_names(self) -> tuple[str, str]:
return (SERVICE_UNLOCK, SERVICE_LOCK)
Expand Down Expand Up @@ -193,7 +192,7 @@ def _msg_generator(
) -> Callable[[str, ReadOnlyDict[Mapping[str, Any]]], str | int]:
return (
lambda state, attributes: MSG_ON
if state in [STATE_ON, STATE_CLEANING]
if state in [STATE_ON, VacuumActivity.CLEANING]
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparison with VacuumActivity.CLEANING will fail because state is a string but VacuumActivity.CLEANING is an enum. The enum needs to be converted to its string value for comparison.

Change to:

if state in [STATE_ON, VacuumActivity.CLEANING.value]

or use:

if state in [STATE_ON, str(VacuumActivity.CLEANING)]
Suggested change
if state in [STATE_ON, VacuumActivity.CLEANING]
if state in [STATE_ON, VacuumActivity.CLEANING.value]

Copilot uses AI. Check for mistakes.
else MSG_OFF
)

Expand Down