-
Notifications
You must be signed in to change notification settings - Fork 6
Move name config to be per device for easier management of the config #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,8 +20,8 @@ class ZigbeeFloorplanCard extends HTMLElement { | |
| if (!config.image) { | ||
| throw new Error('You need to define an image'); | ||
| } | ||
| if (!config.device_coordinates) { | ||
| throw new Error('You need to define device_coordinates'); | ||
| if (!config.devices) { | ||
| throw new Error('You need to define devices'); | ||
| } | ||
|
|
||
| // Validate and sanitize config values | ||
|
|
@@ -32,13 +32,12 @@ class ZigbeeFloorplanCard extends HTMLElement { | |
| this._config = { | ||
| entity: this._sanitizeString(config.entity), | ||
| image: this._sanitizeUrl(config.image), | ||
| device_coordinates: config.device_coordinates, | ||
| devices: config.devices, | ||
| image_width: imageWidth, | ||
| image_height: imageHeight, | ||
| circle_radius: circleRadius, | ||
| show_labels: config.show_labels !== false, | ||
| show_link_lqi: config.show_link_lqi === true, | ||
| friendly_names: config.friendly_names || {}, | ||
| mqtt_base_topic: this._sanitizeString(config.mqtt_base_topic || 'zigbee2mqtt') | ||
| }; | ||
|
Comment on lines
32
to
42
|
||
| } | ||
|
|
@@ -544,8 +543,8 @@ class ZigbeeFloorplanCard extends HTMLElement { | |
| } | ||
| processedLinks.add(linkKey); | ||
|
|
||
| const sourceCoords = this._config.device_coordinates[sourceAddr]; | ||
| const targetCoords = this._config.device_coordinates[targetAddr]; | ||
| const sourceCoords = this._config.devices[sourceAddr]; | ||
| const targetCoords = this._config.devices[targetAddr]; | ||
|
|
||
| if (sourceCoords && targetCoords) { | ||
| const lqi = link.lqi || link.linkquality || 0; | ||
|
|
@@ -600,9 +599,9 @@ class ZigbeeFloorplanCard extends HTMLElement { | |
|
|
||
| nodes.forEach(node => { | ||
| const ieeeAddr = node.ieeeAddr; | ||
| const coords = this._config.device_coordinates[ieeeAddr]; | ||
| const device = this._config.devices[ieeeAddr]; | ||
|
|
||
| if (coords) { | ||
| if (device) { | ||
| const deviceType = node.type || 'EndDevice'; // Coordinator, Router, EndDevice | ||
| const deviceClass = deviceType === 'Coordinator' ? 'coordinator' : | ||
| deviceType === 'Router' ? 'router' : 'end-device'; | ||
|
|
@@ -611,8 +610,8 @@ class ZigbeeFloorplanCard extends HTMLElement { | |
| // Draw circle | ||
| svgDevices.push(` | ||
| <circle | ||
| cx="${parseFloat(coords.x)}" | ||
| cy="${parseFloat(coords.y)}" | ||
| cx="${parseFloat(device.x)}" | ||
| cy="${parseFloat(device.y)}" | ||
| r="${parseInt(this._config.circle_radius)}" | ||
| class="device-circle ${deviceClass} ${isSelected ? 'selected' : ''}" | ||
| data-ieee="${this._escapeHtml(String(ieeeAddr))}" | ||
|
|
@@ -626,8 +625,8 @@ class ZigbeeFloorplanCard extends HTMLElement { | |
| const safeLabel = this._escapeHtml(String(label)); | ||
| svgDevices.push(` | ||
| <text | ||
| x="${parseFloat(coords.x)}" | ||
| y="${parseFloat(coords.y) + parseInt(this._config.circle_radius) + 15}" | ||
| x="${parseFloat(device.x)}" | ||
| y="${parseFloat(device.y) + parseInt(this._config.circle_radius) + 15}" | ||
| class="device-label" | ||
| text-anchor="middle" | ||
| style="pointer-events: none;" | ||
|
|
@@ -641,9 +640,10 @@ class ZigbeeFloorplanCard extends HTMLElement { | |
| } | ||
|
|
||
| getDeviceLabel(ieeeAddr, friendlyName) { | ||
| // Priority 1: Manual override from config | ||
| if (this._config.friendly_names && this._config.friendly_names[ieeeAddr]) { | ||
| return this._config.friendly_names[ieeeAddr]; | ||
| // Priority 1: Name field in devices config | ||
| const device = this._config.devices && this._config.devices[ieeeAddr]; | ||
| if (device && device.name) { | ||
| return device.name; | ||
| } | ||
|
|
||
| // Priority 2: Friendly name from Zigbee2MQTT network map | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setConfignow requiresconfig.devicesand will throw for existing configurations that still use the documenteddevice_coordinateskey from prior versions. To avoid a breaking change (or at least provide a smoother migration), consider acceptingdevice_coordinatesas a fallback/alias (and/or emitting a clear deprecation warning) before throwing an error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can live with that. I will bump the mayor version.