Skip to content

fix: Replace deprecated functions for Core 2025.12.1 compatibility#61

Open
PKC278 wants to merge 3 commits intolarry-wong:mainfrom
PKC278:main
Open

fix: Replace deprecated functions for Core 2025.12.1 compatibility#61
PKC278 wants to merge 3 commits intolarry-wong:mainfrom
PKC278:main

Conversation

@PKC278
Copy link

@PKC278 PKC278 commented Dec 17, 2024

适配 Core 2025.12.1

  • 替换已移除的 area_entities 函数,通过实体注册表按区域过滤传感器

替换已弃用的函数

已弃用函数 新函数
ATTR_MAX_MIREDS ATTR_MIN_COLOR_TEMP_KELVIN
ATTR_MIN_MIREDS ATTR_MAX_COLOR_TEMP_KELVIN
ATTR_COLOR_TEMP ATTR_COLOR_TEMP_KELVIN
STATE_CLEANING VacuumActivity.CLEANING
STATE_LOCKED LockState.LOCKED
STATE_IDLE CameraState.IDLE
StrEnum enum.StrEnum

@Arnie97 Arnie97 mentioned this pull request Oct 19, 2025
Copilot AI review requested due to automatic review settings December 6, 2025 12:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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]
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.
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.
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.
@PKC278 PKC278 changed the title fix: replace deprecated functions fix: Replace deprecated functions for Core 2025.12.1 compatibility Dec 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant