Skip to content

Commit

Permalink
v1.2.16
Browse files Browse the repository at this point in the history
- ZigBee: fix `QueryNodeData`
  • Loading branch information
genemars committed Feb 23, 2023
1 parent 73b8666 commit bd70a89
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions MIG.HomeAutomation/ZigBee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ public void AddNode(ZigBeeNode node)
};
modules.Add(module);
}
if (module.CustomData.Type == ModuleTypes.Generic)
if (module.CustomData.Type == ModuleTypes.Generic || String.IsNullOrEmpty(module.CustomData.ManufacturerName) || String.IsNullOrEmpty(module.CustomData.ModelIdentifier))
{
ControllerEvent("Controller.Status", "Added node " + node.IeeeAddress);
// get manufacturer name and model identifier
Expand Down Expand Up @@ -714,58 +714,59 @@ private async Task QueryNodeData(ZigBeeNode node)
}
ec++;
}
bool updateModules = false;
var module = modules.Find((m) => m.Address == node.IeeeAddress.ToString());
var defaultEndpoint = node.GetEndpoints().FirstOrDefault();
if (defaultEndpoint != null)
{
// Get manufacturer / model
var cluster = defaultEndpoint.GetInputCluster(ZclBasicCluster.CLUSTER_ID);
if (cluster != null)
{
var genericDeviceType = (await cluster.ReadAttributeValue(ZclBasicCluster.ATTR_GENERICDEVICETYPE));
if (genericDeviceType != null)
string manufacturerName = (string)(await cluster.ReadAttributeValue(ZclBasicCluster.ATTR_MANUFACTURERNAME));
if (manufacturerName != null)
{
OnInterfacePropertyChanged(this.GetDomain(), node.IeeeAddress.ToString(), "ZigBee Node", EventPath_GenericDeviceType, genericDeviceType);
(module?.CustomData as ZigBeeNodeData).ManufacturerName = manufacturerName;
OnInterfacePropertyChanged(this.GetDomain(), node.IeeeAddress.ToString(), "ZigBee Node", EventPath_ManufacturerName, manufacturerName);
}
string modelIdentifier = (string)(await cluster.ReadAttributeValue(ZclBasicCluster.ATTR_MODELIDENTIFIER));
if (modelIdentifier != null)
{
(module?.CustomData as ZigBeeNodeData).ModelIdentifier = modelIdentifier;
OnInterfacePropertyChanged(this.GetDomain(), node.IeeeAddress.ToString(), "ZigBee Node", EventPath_ModelIdentifier, modelIdentifier);
}
string manufacturerName = (string)(await cluster.ReadAttributeValue(ZclBasicCluster.ATTR_MANUFACTURERNAME));
if (manufacturerName != null)
var genericDeviceType = (await cluster.ReadAttributeValue(ZclBasicCluster.ATTR_GENERICDEVICETYPE));
if (genericDeviceType != null)
{
OnInterfacePropertyChanged(this.GetDomain(), node.IeeeAddress.ToString(), "ZigBee Node", EventPath_ManufacturerName, manufacturerName);
OnInterfacePropertyChanged(this.GetDomain(), node.IeeeAddress.ToString(), "ZigBee Node", EventPath_GenericDeviceType, genericDeviceType);
}
updateModules = manufacturerName != null || modelIdentifier != null || genericDeviceType != null;
}
}
// Probe device type
var module = modules.Find((m) => m.Address == node.IeeeAddress.ToString());
if (module != null && module.CustomData.Type == ModuleTypes.Generic)
{
if (colorControl)
{
module.CustomData.Type = ModuleTypes.Color;
UpdateModules();
return;
}
if (levelControl && !occupancySensing)
else if (levelControl && !occupancySensing)
{
module.CustomData.Type = ModuleTypes.Color;
UpdateModules();
return;
}
if (iasZone || occupancySensing || illuminanceMeasurement || temperatureMeasurement || windowCovering || electricalMeasurement || metering)
else if (iasZone || occupancySensing || illuminanceMeasurement || temperatureMeasurement || windowCovering || electricalMeasurement || metering)
{
module.CustomData.Type = ModuleTypes.Sensor;
UpdateModules();
return;
}
if (onOff)
else if (onOff)
{
module.CustomData.Type = ModuleTypes.Switch;
UpdateModules();
return;
}
updateModules = updateModules || module.CustomData.Type != ModuleTypes.Generic;
}
if (updateModules)
{
UpdateModules();
}
}

Expand Down Expand Up @@ -798,6 +799,8 @@ public double Level {
public double LastLevel;
public ushort Transition = 4; // 400ms
public ModuleTypes Type = ModuleTypes.Generic;
public string ManufacturerName = "";
public string ModelIdentifier = "";
}

public class ZigBeeCommandListener : IZigBeeCommandListener
Expand Down

0 comments on commit bd70a89

Please sign in to comment.