mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-10-23 14:22:38 +00:00
fix: Preserve HA name if set in withHomeassistant and remove analog prefix (#32654)
Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
1 parent
ac098810a1
commit
bba9c027c5
4 files changed
+227
-20
No files matched your search
@@ -1046,6 +1046,62 @@ describe("Extension: Bridge", () => {
|
||||
source: "generated",
|
||||
description: "Automatically generated definition",
|
||||
exposes: [
|
||||
{
|
||||
access: 5,
|
||||
description: "Analog Input my_sensor_name on endpoint 1",
|
||||
endpoint: "1",
|
||||
homeassistant: {name: "my_sensor_name"},
|
||||
label: "my_sensor_name",
|
||||
name: "analog_in_temperature",
|
||||
property: "analog_in_temperature_1",
|
||||
type: "numeric",
|
||||
unit: "°C",
|
||||
},
|
||||
{
|
||||
access: 5,
|
||||
description: "Analog Input my_sensor2_name on endpoint 2",
|
||||
endpoint: "2",
|
||||
homeassistant: {name: "my_sensor2_name"},
|
||||
label: "my_sensor2_name",
|
||||
name: "analog_in_temperature",
|
||||
property: "analog_in_temperature_2",
|
||||
type: "numeric",
|
||||
unit: "°C",
|
||||
},
|
||||
{
|
||||
access: 7,
|
||||
description: "Analog Output my_number_name on endpoint 2",
|
||||
endpoint: "2",
|
||||
homeassistant: {name: "my_number_name"},
|
||||
label: "my_number_name",
|
||||
name: "analog_output",
|
||||
property: "analog_output_2",
|
||||
type: "numeric",
|
||||
},
|
||||
{
|
||||
access: 5,
|
||||
description: "Binary Input my_binary_name on endpoint 2",
|
||||
endpoint: "2",
|
||||
homeassistant: {name: "my_binary_name"},
|
||||
label: "my_binary_name",
|
||||
name: "binary_input",
|
||||
property: "binary_input_2",
|
||||
type: "binary",
|
||||
value_off: "OFF",
|
||||
value_on: "ON",
|
||||
},
|
||||
{
|
||||
access: 7,
|
||||
description: "Binary Output my_switch_name on endpoint 2",
|
||||
endpoint: "2",
|
||||
homeassistant: {name: "my_switch_name"},
|
||||
label: "my_switch_name",
|
||||
name: "binary_output",
|
||||
property: "binary_output_2",
|
||||
type: "binary",
|
||||
value_off: "OFF",
|
||||
value_on: "ON",
|
||||
},
|
||||
{
|
||||
access: 1,
|
||||
category: "diagnostic",
|
||||
@@ -1120,9 +1176,17 @@ describe("Extension: Bridge", () => {
|
||||
endpoints: {
|
||||
"1": {
|
||||
bindings: [],
|
||||
clusters: {input: ["genBasic"], output: ["genBasic", "genOnOff", "genLevelCtrl", "genScenes"]},
|
||||
clusters: {input: ["genBasic", "genAnalogInput"], output: ["genBasic", "genOnOff", "genLevelCtrl", "genScenes"]},
|
||||
configured_reportings: [],
|
||||
scenes: [],
|
||||
name: "1",
|
||||
},
|
||||
"2": {
|
||||
bindings: [],
|
||||
clusters: {input: ["genBasic", "genAnalogInput", "genAnalogOutput", "genBinaryInput", "genBinaryOutput"], output: []},
|
||||
configured_reportings: [],
|
||||
scenes: [],
|
||||
name: "2",
|
||||
},
|
||||
},
|
||||
friendly_name: "0x0017880104e45518",
|
||||
@@ -2762,6 +2826,62 @@ describe("Extension: Bridge", () => {
|
||||
source: "generated",
|
||||
description: "Automatically generated definition",
|
||||
exposes: [
|
||||
{
|
||||
access: 5,
|
||||
description: "Analog Input my_sensor_name on endpoint 1",
|
||||
endpoint: "1",
|
||||
homeassistant: {name: "my_sensor_name"},
|
||||
label: "my_sensor_name",
|
||||
name: "analog_in_temperature",
|
||||
property: "analog_in_temperature_1",
|
||||
type: "numeric",
|
||||
unit: "°C",
|
||||
},
|
||||
{
|
||||
access: 5,
|
||||
description: "Analog Input my_sensor2_name on endpoint 2",
|
||||
endpoint: "2",
|
||||
homeassistant: {name: "my_sensor2_name"},
|
||||
label: "my_sensor2_name",
|
||||
name: "analog_in_temperature",
|
||||
property: "analog_in_temperature_2",
|
||||
type: "numeric",
|
||||
unit: "°C",
|
||||
},
|
||||
{
|
||||
access: 7,
|
||||
description: "Analog Output my_number_name on endpoint 2",
|
||||
endpoint: "2",
|
||||
homeassistant: {name: "my_number_name"},
|
||||
label: "my_number_name",
|
||||
name: "analog_output",
|
||||
property: "analog_output_2",
|
||||
type: "numeric",
|
||||
},
|
||||
{
|
||||
access: 5,
|
||||
description: "Binary Input my_binary_name on endpoint 2",
|
||||
endpoint: "2",
|
||||
homeassistant: {name: "my_binary_name"},
|
||||
label: "my_binary_name",
|
||||
name: "binary_input",
|
||||
property: "binary_input_2",
|
||||
type: "binary",
|
||||
value_off: "OFF",
|
||||
value_on: "ON",
|
||||
},
|
||||
{
|
||||
access: 7,
|
||||
description: "Binary Output my_switch_name on endpoint 2",
|
||||
endpoint: "2",
|
||||
homeassistant: {name: "my_switch_name"},
|
||||
label: "my_switch_name",
|
||||
name: "binary_output",
|
||||
property: "binary_output_2",
|
||||
type: "binary",
|
||||
value_off: "OFF",
|
||||
value_on: "ON",
|
||||
},
|
||||
{
|
||||
access: 1,
|
||||
category: "diagnostic",
|
||||
|
||||
@@ -1368,6 +1368,77 @@ describe("Extension: HomeAssistant", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("Should discover analog input on unsupported devices with device class and name", () => {
|
||||
const payload = {
|
||||
availability: [
|
||||
{
|
||||
topic: "zigbee2mqtt/bridge/state",
|
||||
value_template: "{{ value_json.state }}",
|
||||
},
|
||||
],
|
||||
default_entity_id: "sensor.0x0017880104e45518_analog_in_temperature_1",
|
||||
device: {
|
||||
identifiers: ["zigbee2mqtt_0x0017880104e45518"],
|
||||
manufacturer: "notSupportedMfg",
|
||||
model: "Automatically generated definition",
|
||||
model_id: "notSupportedModelID",
|
||||
name: "0x0017880104e45518",
|
||||
via_device: "zigbee2mqtt_bridge_0x00124b00120144ae",
|
||||
},
|
||||
device_class: "temperature",
|
||||
enabled_by_default: true,
|
||||
name: "my_sensor_name",
|
||||
object_id: "0x0017880104e45518_analog_in_temperature_1",
|
||||
origin: origin,
|
||||
state_class: "measurement",
|
||||
state_topic: "zigbee2mqtt/0x0017880104e45518",
|
||||
unique_id: "0x0017880104e45518_analog_in_temperature_1_zigbee2mqtt",
|
||||
unit_of_measurement: "°C",
|
||||
value_template: '{{ value_json["analog_in_temperature_1"] }}',
|
||||
};
|
||||
|
||||
expect(mockMQTTPublishAsync).toHaveBeenCalledWith(
|
||||
"homeassistant/sensor/0x0017880104e45518/analog_in_temperature_1/config",
|
||||
stringify(payload),
|
||||
{
|
||||
retain: true,
|
||||
qos: 1,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("Should discover analog output on unsupported devices", () => {
|
||||
const payload = {
|
||||
availability: [
|
||||
{
|
||||
topic: "zigbee2mqtt/bridge/state",
|
||||
value_template: "{{ value_json.state }}",
|
||||
},
|
||||
],
|
||||
command_topic: "zigbee2mqtt/0x0017880104e45518/2/set/analog_output_2",
|
||||
default_entity_id: "number.0x0017880104e45518_analog_output_2",
|
||||
device: {
|
||||
identifiers: ["zigbee2mqtt_0x0017880104e45518"],
|
||||
manufacturer: "notSupportedMfg",
|
||||
model: "Automatically generated definition",
|
||||
model_id: "notSupportedModelID",
|
||||
name: "0x0017880104e45518",
|
||||
via_device: "zigbee2mqtt_bridge_0x00124b00120144ae",
|
||||
},
|
||||
name: "my_number_name",
|
||||
object_id: "0x0017880104e45518_analog_output_2",
|
||||
origin: origin,
|
||||
state_topic: "zigbee2mqtt/0x0017880104e45518",
|
||||
unique_id: "0x0017880104e45518_analog_output_2_zigbee2mqtt",
|
||||
value_template: '{{ value_json["analog_output_2"] }}',
|
||||
};
|
||||
|
||||
expect(mockMQTTPublishAsync).toHaveBeenCalledWith("homeassistant/number/0x0017880104e45518/analog_output_2/config", stringify(payload), {
|
||||
qos: 1,
|
||||
retain: true,
|
||||
});
|
||||
});
|
||||
|
||||
it("Should apply user configuration after converter compatibility mapping", async () => {
|
||||
settings.set(["devices", "0x18fc2600000d7ae2", "homeassistant", "climate"], {
|
||||
modes: ["off", "heat", "auto"],
|
||||
|
||||
Reference in new issue
Block a user