Skip to content

Commit

Permalink
v1.2.13
Browse files Browse the repository at this point in the history
- ZigBee: fix node add/discovery
  • Loading branch information
genemars committed Feb 14, 2023
1 parent 0b3d9c0 commit ff9edae
Showing 1 changed file with 56 additions and 61 deletions.
117 changes: 56 additions & 61 deletions MIG.HomeAutomation/ZigBee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,12 @@ public void AddNode(ZigBeeNode node)
{
ControllerEvent("Controller.Status", "Added node " + node.IeeeAddress);
// get manufacturer name and model identifier
ReadClusterData(node).Wait();
OnInterfaceModulesChanged(this.GetDomain());
lastAddedNode = node.IeeeAddress.ToString();
Task.Run(() =>
{
ReadClusterData(node).Wait();
OnInterfaceModulesChanged(this.GetDomain());
lastAddedNode = node.IeeeAddress.ToString();
});
}
}
}
Expand Down Expand Up @@ -596,6 +599,7 @@ private async Task SetColorHsb(ZigBeeEndpointAddress endpointAddress, double h,
private async Task ReadClusterData(ZigBeeNode node)
{
var endpoint = node.GetEndpoints().FirstOrDefault();
// Get manufacturer / model
var cluster = endpoint?.GetInputCluster(ZclBasicCluster.CLUSTER_ID);
if (cluster != null)
{
Expand All @@ -609,66 +613,57 @@ private async Task ReadClusterData(ZigBeeNode node)
{
OnInterfacePropertyChanged(this.GetDomain(), node.IeeeAddress.ToString(), "ZigBee Node", EventPath_ManufacturerName, manufacturerName);
}
// try to probe / read current device values
var module = modules.Find((m) => m.Address == node.IeeeAddress.ToString());
}
//
// Try to probe / read current device values
//
var module = modules.Find((m) => m.Address == node.IeeeAddress.ToString());
if (module != null && module.CustomData.Type == ModuleTypes.Generic)
{

// Color Light Bulb
if (module != null && module.CustomData.Type == ModuleTypes.Generic)
var colorCluster = endpoint?.GetInputCluster(ZclColorControlCluster.CLUSTER_ID);
//byte colorCapabilities = (byte)(await colorCluster.ReadAttributeValue(ZclColorControlCluster.ATTR_COLORMODE));
//OnInterfacePropertyChanged(this.GetDomain(), node.IeeeAddress.ToString(), "ZigBee Node", ModuleEvents.Status_Level, level / 254D);
if (colorCluster != null)
{
try
{
var colorCluster = endpoint?.GetInputCluster(ZclColorControlCluster.CLUSTER_ID);
//byte colorCapabilities = (byte)(await colorCluster.ReadAttributeValue(ZclColorControlCluster.ATTR_COLORMODE));
//OnInterfacePropertyChanged(this.GetDomain(), node.IeeeAddress.ToString(), "ZigBee Node", ModuleEvents.Status_Level, level / 254D);
if (colorCluster != null)
{
module.CustomData.Type = ModuleTypes.Color;
return;
}
}
catch (Exception e)
{
// Console.WriteLine(e);
}
// Dimmer
try
{
// Binary switch level / basic.get
var levelCluster = endpoint?.GetInputCluster(ZclLevelControlCluster.CLUSTER_ID);
byte level = (byte)(await levelCluster.ReadAttributeValue(ZclLevelControlCluster.ATTR_CURRENTLEVEL));
OnInterfacePropertyChanged
(
this.GetDomain(),
node.IeeeAddress.ToString(),
"ZigBee Node",
ModuleEvents.Status_Level,
level / 254D
);
module.CustomData.Type = ModuleTypes.Dimmer;
return;
}
catch (Exception e)
{
// Console.WriteLine(e);
}
// Sensor
try
{
var levelCluster = endpoint?.GetInputCluster(ZclIasZoneCluster.CLUSTER_ID);
byte level = (byte)(await levelCluster.ReadAttributeValue(ZclIasZoneCluster.ATTR_ZONESTATUS));
OnInterfacePropertyChanged
(
this.GetDomain(),
node.IeeeAddress.ToString(),
"ZigBee Node",
ModuleEvents.Status_Level,
level
);
module.CustomData.Type = ModuleTypes.Sensor;
}
catch (Exception e)
{
// Console.WriteLine(e);
}
module.CustomData.Type = ModuleTypes.Color;
UpdateModules();
return;
}

// Dimmer or Binary switch level / basic.get
var levelCluster = endpoint?.GetInputCluster(ZclLevelControlCluster.CLUSTER_ID);
if (levelCluster != null)
{
byte level = (byte)(await levelCluster.ReadAttributeValue(ZclLevelControlCluster.ATTR_CURRENTLEVEL));
OnInterfacePropertyChanged
(
this.GetDomain(),
node.IeeeAddress.ToString(),
"ZigBee Node",
ModuleEvents.Status_Level,
level / 254D
);
module.CustomData.Type = ModuleTypes.Dimmer;
UpdateModules();
return;
}

// Sensor
var iasZoneCluster = endpoint?.GetInputCluster(ZclIasZoneCluster.CLUSTER_ID);
if (iasZoneCluster != null)
{
byte level = (byte)(await iasZoneCluster.ReadAttributeValue(ZclIasZoneCluster.ATTR_ZONESTATUS));
OnInterfacePropertyChanged
(
this.GetDomain(),
node.IeeeAddress.ToString(),
"ZigBee Node",
ModuleEvents.Status_Level,
level
);
module.CustomData.Type = ModuleTypes.Sensor;
UpdateModules();
}
}
Expand Down

0 comments on commit ff9edae

Please sign in to comment.