fix: Replace deprecated functions for Core 2025.12.1 compatibility#61
fix: Replace deprecated functions for Core 2025.12.1 compatibility#61PKC278 wants to merge 3 commits intolarry-wong:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the bemfa Home Assistant integration to replace deprecated constants and functions scheduled for removal in HA Core 2025.5, 2025.10, and 2026.1. The changes include migrating from deprecated string constants to enum-based constants, updating light color temperature attributes from mireds to kelvin, replacing the deprecated StrEnum import, and updating the paho-mqtt client initialization.
Key changes:
- Replaced deprecated state constants (STATE_CLEANING, STATE_LOCKED, STATE_IDLE) with new enum types (VacuumActivity, LockState, CameraState)
- Converted light color temperature from mireds-based attributes to kelvin-based attributes
- Updated MQTT client initialization with new paho-mqtt API (callback_api_version parameter)
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| custom_components/bemfa/sync_switch.py | Replaced deprecated state constants with enum types for camera, lock, and vacuum entities |
| custom_components/bemfa/sync_sensor.py | Replaced deprecated area_entities template helper with entity registry API and minor formatting improvements |
| custom_components/bemfa/sync_light.py | Converted light color temperature attributes from mireds to kelvin equivalents |
| custom_components/bemfa/mqtt.py | Updated MQTT client initialization to use new paho-mqtt 2.x API with callback_api_version parameter |
| custom_components/bemfa/manifest.json | Updated paho-mqtt requirement by removing version pin |
| custom_components/bemfa/const.py | Replaced homeassistant.backports.enum.StrEnum with standard library enum.StrEnum |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return ( | ||
| lambda state, attributes: MSG_ON | ||
| if state in [STATE_ON, STATE_CLEANING] | ||
| if state in [STATE_ON, VacuumActivity.CLEANING] |
There was a problem hiding this comment.
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)]| if state in [STATE_ON, VacuumActivity.CLEANING] | |
| if state in [STATE_ON, VacuumActivity.CLEANING.value] |
| 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 |
There was a problem hiding this comment.
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_ONor use:
return lambda state, attributes: MSG_OFF if state == str(CameraState.IDLE) else MSG_ON| 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 |
| 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 |
There was a problem hiding this comment.
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_ONor use:
return lambda state, attributes: MSG_OFF if state == str(LockState.LOCKED) else MSG_ON| 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 |
适配 Core 2025.12.1
替换已弃用的函数
ATTR_MAX_MIREDSATTR_MIN_COLOR_TEMP_KELVINATTR_MIN_MIREDSATTR_MAX_COLOR_TEMP_KELVINATTR_COLOR_TEMPATTR_COLOR_TEMP_KELVINSTATE_CLEANINGVacuumActivity.CLEANINGSTATE_LOCKEDLockState.LOCKEDSTATE_IDLECameraState.IDLEStrEnumenum.StrEnum