$ show PiotrMachowski/lovelace-xiaomi-vacuum-map-card
This repository implements a custom Lovelace card for Home Assistant that displays an interactive map of a robot vacuum's environment. It allows users to select zones, rooms, points, or paths for cleaning and sends corresponding service calls to the vacuum. The card supports multiple vacuum platforms (Xiaomi Miio, Roborock, Valetudo, Neato, Dreame, Roomba, etc.) via platform-specific templates that define map modes, tiles, and icons. It includes a visual editor, localization in 28 languages, pinch-zoom functionality, and a configurable tile/icon system. The architecture is a single-page web component built with LitElement, with modular internal components for map objects, map modes, generators, and UI elements. It relies on Home Assistant frontend internals and custom-card-helpers. The codebase is well-structured with reusable patterns like dependency injection (Context), coordinate transformation (CoordinatesConverter), and template-based service call generation (ServiceCallSchema). However, it has some technical drift due to deprecated rollup plugins, polyfills for legacy browsers, and tight coupling to HA APIs that may break with updates.
The LLM identified 4 files worth highlighting for reuse:
A standalone LitElement web component that provides pinch-to-zoom and pan functionality for any container element. It is self-contained, with no internal dependencies beyond Lit, and can be extracted and reused in any web application that needs zoom/pan on an image or canvas. It handles touch and mouse events, calculates transform matrices, and emits events for zoom/pan changes.
A utility class that converts between image pixel coordinates and vacuum world coordinates using calibration points. It supports both affine (3-point) and perspective (4-point) transformations. The class is self-contained, takes an array of calibration points, and provides methods to convert points and distances. It could be extracted and reused in any project that needs to map between two coordinate systems given known reference points.
A class that defines a service call schema with template variables (e.g., [[entity_id]], [[selection]], [[point_x]]) and provides a method to build the final service data object by substituting values. It is generic and not tied to any specific vacuum platform; it could be reused in any Home Assistant custom card or automation that needs to construct dynamic service calls from user input.
A reusable LitElement component that renders a dropdown menu with configurable items, icons, and actions. It is self-contained, uses Lit's reactive properties, and emits events on item selection. It could be extracted and used in any web component that needs a dropdown menu, independent of Home Assistant.