- 积分
- 308
- 金钱
- 233
- 威望
- 0
- 贡献
- 0
- HASS币
- 0
中级会员
- 积分
- 308
- 金钱
- 233
- HASS币
- 0
|
修改代码sync_sensor.py
删除17行的导入
from .sync import SYNC_TYPES, Sync
_LOGGING = logging.getLogger(__name__)
# 增加以下代码
def area_entities(hass: HomeAssistant, area_id: str) -> list[str]:
ar = area_registry.async_get(hass)
target_area = ar.async_get_area(area_id)
if not target_area:
return []
# 递归获取当前区域 + 所有子区域的实体ID
entity_ids = []
for entity_id in hass.states.async_entity_ids():
state = hass.states.get(entity_id)
if state and state.attributes.get("area_id") == area_id:
entity_ids.append(entity_id)
for sub_area in ar.async_get_children(area_id):
entity_ids.extend(area_entities(hass, sub_area.id))
return list(set(entity_ids)) |
|