Calendar filtered
This commit is contained in:
parent
f998b2a07d
commit
23af597701
1 changed files with 26 additions and 16 deletions
|
|
@ -529,13 +529,18 @@ def summarize_snapshot(snapshot: dict[str, Any]) -> str:
|
||||||
snapshot.get("states", []),
|
snapshot.get("states", []),
|
||||||
key=lambda state: (-entity_importance(state.get("entity_id", ""), state.get("attributes", {})), state.get("entity_id", "")),
|
key=lambda state: (-entity_importance(state.get("entity_id", ""), state.get("attributes", {})), state.get("entity_id", "")),
|
||||||
)
|
)
|
||||||
|
calendar_events = snapshot.get("calendar_events", [])
|
||||||
|
calendar_entity_ids_with_events = {calendar.get("entity_id") for calendar in calendar_events if calendar.get("events")}
|
||||||
for state in states:
|
for state in states:
|
||||||
|
entity_id = state.get("entity_id", "")
|
||||||
|
if entity_id.startswith("calendar.") and entity_id not in calendar_entity_ids_with_events:
|
||||||
|
continue
|
||||||
attrs = state.get("attributes", {})
|
attrs = state.get("attributes", {})
|
||||||
name = attrs.get("friendly_name", state.get("entity_id"))
|
name = attrs.get("friendly_name", entity_id)
|
||||||
unit = attrs.get("unit_of_measurement", "")
|
unit = attrs.get("unit_of_measurement", "")
|
||||||
value = f"{state.get('state')} {unit}".strip()
|
value = f"{state.get('state')} {unit}".strip()
|
||||||
score = entity_importance(state.get("entity_id", ""), attrs)
|
score = entity_importance(entity_id, attrs)
|
||||||
lines.append(f"- importance={score} {name} ({state.get('entity_id')}): {value}; last_changed={display_time(state.get('last_changed'))}")
|
lines.append(f"- importance={score} {name} ({entity_id}): {value}; last_changed={display_time(state.get('last_changed'))}")
|
||||||
forecast = snapshot.get("weather_forecast") or {}
|
forecast = snapshot.get("weather_forecast") or {}
|
||||||
if forecast:
|
if forecast:
|
||||||
lines.append("Direct weather forecast:")
|
lines.append("Direct weather forecast:")
|
||||||
|
|
@ -557,26 +562,30 @@ def summarize_snapshot(snapshot: dict[str, Any]) -> str:
|
||||||
f"wind_max={day.get('wind_speed_max_kmh')}km/h; gusts={day.get('wind_gusts_max_kmh')}km/h; "
|
f"wind_max={day.get('wind_speed_max_kmh')}km/h; gusts={day.get('wind_gusts_max_kmh')}km/h; "
|
||||||
f"sunrise={day.get('sunrise')}; sunset={day.get('sunset')}"
|
f"sunrise={day.get('sunrise')}; sunset={day.get('sunset')}"
|
||||||
)
|
)
|
||||||
lines.append("Upcoming calendar events:")
|
if calendar_events:
|
||||||
for calendar in snapshot.get("calendar_events", []):
|
lines.append("Upcoming calendar appointments:")
|
||||||
lines.append(f"- {calendar.get('entity_id')}:")
|
for calendar in calendar_events:
|
||||||
for event in calendar.get("events", []):
|
lines.append(f"- {calendar.get('entity_id')}:")
|
||||||
details = []
|
for event in calendar.get("events", []):
|
||||||
if event.get("location"):
|
details = []
|
||||||
details.append(f"location={event.get('location')}")
|
if event.get("location"):
|
||||||
if event.get("description"):
|
details.append(f"location={event.get('location')}")
|
||||||
details.append(f"description={event.get('description')}")
|
if event.get("description"):
|
||||||
detail_text = f"; {'; '.join(details)}" if details else ""
|
details.append(f"description={event.get('description')}")
|
||||||
lines.append(f" - {event.get('start')} to {event.get('end')}: {event.get('summary')}{detail_text}")
|
detail_text = f"; {'; '.join(details)}" if details else ""
|
||||||
|
lines.append(f" - {event.get('start')} to {event.get('end')}: {event.get('summary')}{detail_text}")
|
||||||
lines.append("Recently changed entities:")
|
lines.append("Recently changed entities:")
|
||||||
history = sorted(
|
history = sorted(
|
||||||
snapshot.get("history", []),
|
snapshot.get("history", []),
|
||||||
key=lambda item: (-entity_importance(item.get("entity_id", "")), item.get("entity_id", "")),
|
key=lambda item: (-entity_importance(item.get("entity_id", "")), item.get("entity_id", "")),
|
||||||
)
|
)
|
||||||
for item in history:
|
for item in history:
|
||||||
|
entity_id = item.get("entity_id", "")
|
||||||
|
if entity_id.startswith("calendar.") and entity_id not in calendar_entity_ids_with_events:
|
||||||
|
continue
|
||||||
transitions = ", ".join(f"{x.get('state')} @ {display_time(x.get('last_changed'))}" for x in item.get("recent_states", [])[-8:])
|
transitions = ", ".join(f"{x.get('state')} @ {display_time(x.get('last_changed'))}" for x in item.get("recent_states", [])[-8:])
|
||||||
score = entity_importance(item.get("entity_id", ""))
|
score = entity_importance(entity_id)
|
||||||
lines.append(f"- importance={score} {item.get('entity_id')}: {transitions}")
|
lines.append(f"- importance={score} {entity_id}: {transitions}")
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -668,6 +677,7 @@ short paragraphs, and readable bullet lists. Remain factual and privacy-aware. I
|
||||||
- Suggested Home Assistant automations or fixes
|
- Suggested Home Assistant automations or fixes
|
||||||
|
|
||||||
Distinguish strong evidence from guesses. Do not invent facts not supported by the data.
|
Distinguish strong evidence from guesses. Do not invent facts not supported by the data.
|
||||||
|
Mention calendar/appointment analysis only when the data contains upcoming calendar appointments; do not comment on empty calendars or calendar state noise.
|
||||||
{extra_block}{previous_block}
|
{extra_block}{previous_block}
|
||||||
TODAY'S DATA:
|
TODAY'S DATA:
|
||||||
{input_summary}
|
{input_summary}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue