Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
z2m
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Go
z2m
Commits
ac745cb1
Commit
ac745cb1
authored
4 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
We can now add or remove zigbee devices
We can now add or remove zigbee devices without restarting the app.
parent
647c8577
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
gateway.go
+27
-0
27 additions, 0 deletions
gateway.go
z2m.go
+0
-1
0 additions, 1 deletion
z2m.go
with
27 additions
and
1 deletion
gateway.go
+
27
−
0
View file @
ac745cb1
...
...
@@ -30,11 +30,21 @@ func (gw *Gateway) GetZDevice(name string) *Z2MDevice {
}
func
(
gw
*
Gateway
)
AddZDevice
(
zDev
*
Z2MDevice
)
{
for
_
,
xDev
:=
range
zDev
.
XAALDevices
{
dev
:=
xDev
.
getXAALDevice
()
slog
.
Debug
(
"Adding device"
,
"dev"
,
dev
.
String
())
gw
.
Engine
.
AddDevice
(
dev
)
}
gw
.
Devices
[
zDev
.
FriendlyName
]
=
zDev
zDev
.
Gateway
=
gw
}
func
(
gw
*
Gateway
)
RemoveZDevice
(
zDev
*
Z2MDevice
)
{
for
_
,
xDev
:=
range
zDev
.
XAALDevices
{
dev
:=
xDev
.
getXAALDevice
()
slog
.
Debug
(
"Removing device"
,
"dev"
,
dev
.
String
())
gw
.
Engine
.
RemoveDevice
(
dev
)
}
zDev
.
Gateway
=
nil
delete
(
gw
.
Devices
,
zDev
.
FriendlyName
)
}
...
...
@@ -72,20 +82,37 @@ func (gw *Gateway) mqttPublishHander(client mqtt.Client, msg mqtt.Message) {
// if they don't exist
func
(
gw
*
Gateway
)
jsonParseDevices
(
msg
mqtt
.
Message
)
{
var
devices
[]
Z2MDevice
slog
.
Debug
(
"Parsing devices"
)
err
:=
json
.
Unmarshal
(
msg
.
Payload
(),
&
devices
)
if
err
!=
nil
{
slog
.
Error
(
"Error decoding JSON"
,
"err"
,
err
)
}
// search for new devices
for
_
,
zDev
:=
range
devices
{
known
:=
gw
.
GetZDevice
(
zDev
.
FriendlyName
)
if
known
!=
nil
{
continue
}
slog
.
Debug
(
"Found new device"
,
"name"
,
zDev
.
FriendlyName
)
zDev
.
Dump
()
zDev
.
setupXAALDevices
(
gw
)
gw
.
AddZDevice
(
&
zDev
)
zDev
.
Sync
()
// zDev.Available()
}
// search for deleted devices
for
_
,
zDev
:=
range
gw
.
GetZDevices
()
{
found
:=
false
for
_
,
dev
:=
range
devices
{
if
dev
.
FriendlyName
==
zDev
.
FriendlyName
{
found
=
true
break
}
}
if
!
found
{
slog
.
Debug
(
"Device removed"
,
"name"
,
zDev
.
FriendlyName
)
gw
.
RemoveZDevice
(
zDev
)
}
}
}
This diff is collapsed.
Click to expand it.
z2m.go
+
0
−
1
View file @
ac745cb1
...
...
@@ -125,7 +125,6 @@ func (zDev *Z2MDevice) setupXAALDevices(gw *Gateway) {
zDev
.
XAALDevices
=
append
(
zDev
.
XAALDevices
,
dev
)
xaalDev
:=
dev
.
getXAALDevice
()
xaalDev
.
GroupID
=
grpAdd
gw
.
Engine
.
AddDevice
(
xaalDev
)
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment