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
6 changes: 5 additions & 1 deletion custom_components/home_maintenance/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ async def async_update(self) -> None:

async def async_added_to_hass(self) -> None:
"""Run when entity is added to Home Assistant."""
registry = er.async_get(self.hass)
if self._labels:
registry = er.async_get(self.hass)
if registry.async_get(self.entity_id):
registry.async_update_entity(self.entity_id, labels=set(self._labels))
area_id = self.task.get("area_id")
if area_id:
if registry.async_get(self.entity_id):
registry.async_update_entity(self.entity_id, area_id=area_id)
16 changes: 8 additions & 8 deletions custom_components/home_maintenance/panel/dist/main.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
},
"label": {
"heading": "Bezeichnung(en)"
},
"area": {
"heading": "Bereich"
}
},
"sections": {
Expand Down Expand Up @@ -87,6 +90,9 @@
},
"label": {
"heading": "Bezeichnung(en)"
},
"area": {
"heading": "Bereich"
}
},
"sections": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
},
"label": {
"heading": "Label(s)"
},
"area": {
"heading": "Area"
}
},
"sections": {
Expand Down Expand Up @@ -87,6 +90,9 @@
},
"label": {
"heading": "Label(s)"
},
"area": {
"heading": "Area"
}
},
"sections": {
Expand Down
17 changes: 16 additions & 1 deletion custom_components/home_maintenance/panel/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface TaskFormData {
icon: string;
label: string[];
tag: string;
area: string;
}

export class HomeMaintenancePanel extends LitElement {
Expand All @@ -45,6 +46,7 @@ export class HomeMaintenancePanel extends LitElement {
icon: "",
label: [],
tag: "",
area: "",
};
private _advancedOpen: boolean = false;

Expand All @@ -58,6 +60,7 @@ export class HomeMaintenancePanel extends LitElement {
icon: "",
label: [],
tag: "",
area: "",
};

// Shared overflow menu state
Expand Down Expand Up @@ -262,6 +265,7 @@ export class HomeMaintenancePanel extends LitElement {
{ name: "icon", selector: { icon: {} }, },
{ name: "label", selector: { label: { multiple: true } }, },
{ name: "tag", selector: { entity: { filter: { domain: "tag" } } }, },
{ name: "area", selector: { area: {} }, },
]
};

Expand All @@ -286,6 +290,7 @@ export class HomeMaintenancePanel extends LitElement {
{ name: "icon", selector: { icon: {} }, },
{ name: "label", selector: { label: { multiple: true } }, },
{ name: "tag", selector: { entity: { filter: { domain: "tag" } } }, },
{ name: "area", selector: { area: {} }, },
]
};

Expand Down Expand Up @@ -339,6 +344,7 @@ export class HomeMaintenancePanel extends LitElement {
icon: "",
label: [],
tag: "",
area: "",
};

this.tasks = await loadTasks(this.hass!);
Expand All @@ -353,6 +359,7 @@ export class HomeMaintenancePanel extends LitElement {
icon: "",
label: [],
tag: "",
area: "",
};
}

Expand Down Expand Up @@ -551,7 +558,7 @@ export class HomeMaintenancePanel extends LitElement {
}

private async _handleAddTaskClick() {
const { title, interval_value, interval_type, last_performed, tag, icon, label } = this._formData;
const { title, interval_value, interval_type, last_performed, tag, icon, label, area } = this._formData;

if (!title?.trim() || !interval_value || !interval_type) {
const msg = localize("panel.cards.new.alerts.required", this.hass!.language);
Expand All @@ -567,6 +574,7 @@ export class HomeMaintenancePanel extends LitElement {
tag_id: tag?.trim() || undefined,
icon: icon?.trim() || "mdi:calendar-check",
labels: label ?? [],
area_id: area?.trim() || undefined,
};

try {
Expand Down Expand Up @@ -605,6 +613,7 @@ export class HomeMaintenancePanel extends LitElement {
icon: task.icon ?? "",
label: labels.map((l) => l.label_id),
tag: task.tag_id ?? "",
area: entity?.area_id ?? "",
};

await this.updateComplete;
Expand Down Expand Up @@ -634,6 +643,12 @@ export class HomeMaintenancePanel extends LitElement {
updates.tag_id = null;
}

if (this._editFormData.area && this._editFormData.area.trim() !== "") {
updates.area_id = this._editFormData.area.trim();
} else {
updates.area_id = null;
}

const payload = {
task_id: this._editingTaskId,
updates,
Expand Down
1 change: 1 addition & 0 deletions custom_components/home_maintenance/panel/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,5 @@ export interface Task {
last_performed: string;
tag_id?: string;
icon?: string;
area_id?: string | null;
}
25 changes: 25 additions & 0 deletions custom_components/home_maintenance/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class HomeMaintenanceTask:
last_performed: str = attr.ib()
tag_id: str | None = attr.ib(default=None)
icon: str | None = attr.ib(default=None)
area_id: str | None = attr.ib(default=None)


class TaskStore:
Expand Down Expand Up @@ -121,6 +122,20 @@ def add(
self.hass.data[const.DOMAIN]["entities"][task.id] = entity
self._save()

# Set area_id on the entity if provided
if task.area_id:
er = entity_registry.async_get(self.hass)
entity_entry = next(
(
entry
for entry in er.entities.values()
if entry.unique_id == task.id and entry.platform == const.DOMAIN
),
None,
)
if entity_entry:
er.async_update_entity(entity_entry.entity_id, area_id=task.area_id)

return entity.unique_id

def delete(self, task_id: str) -> None:
Expand Down Expand Up @@ -167,6 +182,16 @@ def update_task(self, task_id: str, updated: dict) -> None:
task.tag_id = tag_id if tag_id else None
entity.task["tag_id"] = tag_id if tag_id else None

if "area_id" in updated:
area_id = updated["area_id"]
task.area_id = area_id if area_id else None
registry = entity_registry.async_get(self.hass)
if registry.async_get(entity.entity_id):
registry.async_update_entity(
entity.entity_id,
area_id=area_id or None,
)

if "labels" in updated:
registry = entity_registry.async_get(self.hass)
if registry.async_get(entity.entity_id):
Expand Down
2 changes: 2 additions & 0 deletions custom_components/home_maintenance/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def websocket_add_task(
last_performed=last_performed,
tag_id=msg.get("tag_id"),
icon=msg.get("icon"),
area_id=msg.get("area_id"),
)

labels = msg.get("labels", [])
Expand Down Expand Up @@ -187,6 +188,7 @@ async def async_register_websockets(hass: HomeAssistant) -> None:
vol.Optional("tag_id"): str,
vol.Optional("icon"): str,
vol.Optional("labels"): [str],
vol.Optional("area_id"): vol.Any(str, None),
}
),
)
Expand Down