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
28074d42
Commit
28074d42
authored
6 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Added support for sync
parent
45cb7234
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
xaal.go
+40
-26
40 additions, 26 deletions
xaal.go
z2m.go
+2
-12
2 additions, 12 deletions
z2m.go
with
42 additions
and
38 deletions
xaal.go
+
40
−
26
View file @
28074d42
...
@@ -35,13 +35,13 @@ type Battery struct {
...
@@ -35,13 +35,13 @@ type Battery struct {
type
PowerRelay
struct
{
type
PowerRelay
struct
{
XAALDevice
XAALDevice
Z2MDevice
Z2MDevice
Z2MDevice
Property
string
Property
string
}
}
type
Lamp
struct
{
type
Lamp
struct
{
XAALDevice
XAALDevice
Z2MDevice
Z2MDevice
Z2MDevice
}
}
type
XAALDeviceInterface
interface
{
type
XAALDeviceInterface
interface
{
...
@@ -71,8 +71,10 @@ func NewContact(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
...
@@ -71,8 +71,10 @@ func NewContact(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
}
}
func
(
dev
*
Contact
)
update
(
payload
map
[
string
]
interface
{})
{
func
(
dev
*
Contact
)
update
(
payload
map
[
string
]
interface
{})
{
value
:=
payload
[
"contact"
]
.
(
bool
)
value
,
exists
:=
payload
[
"contact"
]
.
(
bool
)
dev
.
GetAttribute
(
"detected"
)
.
SetValue
(
!
value
)
if
exists
{
dev
.
GetAttribute
(
"detected"
)
.
SetValue
(
!
value
)
}
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
...
@@ -85,8 +87,10 @@ func NewThermometer(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
...
@@ -85,8 +87,10 @@ func NewThermometer(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
}
}
func
(
dev
*
Thermometer
)
update
(
payload
map
[
string
]
interface
{})
{
func
(
dev
*
Thermometer
)
update
(
payload
map
[
string
]
interface
{})
{
value
:=
payload
[
"temperature"
]
.
(
float64
)
value
,
exists
:=
payload
[
"temperature"
]
.
(
float64
)
dev
.
GetAttribute
(
"temperature"
)
.
SetValue
(
value
)
if
exists
{
dev
.
GetAttribute
(
"temperature"
)
.
SetValue
(
value
)
}
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
...
@@ -99,8 +103,10 @@ func NewHygrometer(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
...
@@ -99,8 +103,10 @@ func NewHygrometer(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
}
}
func
(
dev
*
Hygrometer
)
update
(
payload
map
[
string
]
interface
{})
{
func
(
dev
*
Hygrometer
)
update
(
payload
map
[
string
]
interface
{})
{
value
:=
payload
[
"humidity"
]
.
(
float64
)
value
,
exists
:=
payload
[
"humidity"
]
.
(
float64
)
dev
.
GetAttribute
(
"humidity"
)
.
SetValue
(
value
)
if
exists
{
dev
.
GetAttribute
(
"humidity"
)
.
SetValue
(
value
)
}
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
...
@@ -113,9 +119,11 @@ func NewLinkQuality(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
...
@@ -113,9 +119,11 @@ func NewLinkQuality(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
}
}
func
(
dev
*
LinkQuality
)
update
(
payload
map
[
string
]
interface
{})
{
func
(
dev
*
LinkQuality
)
update
(
payload
map
[
string
]
interface
{})
{
value
:=
payload
[
"linkquality"
]
.
(
float64
)
value
,
exists
:=
payload
[
"linkquality"
]
.
(
float64
)
value
=
math
.
Round
(
value
/
255
*
100
)
if
exists
{
dev
.
GetAttribute
(
"level"
)
.
SetValue
(
value
)
value
=
math
.
Round
(
value
/
255
*
100
)
dev
.
GetAttribute
(
"level"
)
.
SetValue
(
value
)
}
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
...
@@ -128,8 +136,10 @@ func NewBattery(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
...
@@ -128,8 +136,10 @@ func NewBattery(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
}
}
func
(
dev
*
Battery
)
update
(
payload
map
[
string
]
interface
{})
{
func
(
dev
*
Battery
)
update
(
payload
map
[
string
]
interface
{})
{
value
:=
payload
[
"battery"
]
.
(
float64
)
value
,
exists
:=
payload
[
"battery"
]
.
(
float64
)
dev
.
GetAttribute
(
"level"
)
.
SetValue
(
value
)
if
exists
{
dev
.
GetAttribute
(
"level"
)
.
SetValue
(
value
)
}
}
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
...
@@ -145,12 +155,14 @@ func NewPowerRelay(addr uuid.UUID, zDev *Z2MDevice, property string) XAALDeviceI
...
@@ -145,12 +155,14 @@ func NewPowerRelay(addr uuid.UUID, zDev *Z2MDevice, property string) XAALDeviceI
}
}
func
(
dev
*
PowerRelay
)
update
(
payload
map
[
string
]
interface
{})
{
func
(
dev
*
PowerRelay
)
update
(
payload
map
[
string
]
interface
{})
{
value
:=
payload
[
dev
.
Property
]
.
(
string
)
value
,
exists
:=
payload
[
dev
.
Property
]
.
(
string
)
power
:=
dev
.
GetAttribute
(
"power"
)
if
exists
{
if
value
==
"ON"
{
power
:=
dev
.
GetAttribute
(
"power"
)
power
.
SetValue
(
true
)
if
value
==
"ON"
{
}
else
if
value
==
"OFF"
{
power
.
SetValue
(
true
)
power
.
SetValue
(
false
)
}
else
if
value
==
"OFF"
{
power
.
SetValue
(
false
)
}
}
}
}
}
...
@@ -187,12 +199,14 @@ func NewLamp(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
...
@@ -187,12 +199,14 @@ func NewLamp(addr uuid.UUID, zDev *Z2MDevice) XAALDeviceInterface {
}
}
func
(
dev
*
Lamp
)
update
(
payload
map
[
string
]
interface
{})
{
func
(
dev
*
Lamp
)
update
(
payload
map
[
string
]
interface
{})
{
value
:=
payload
[
"state"
]
.
(
string
)
value
,
exists
:=
payload
[
"state"
]
.
(
string
)
light
:=
dev
.
GetAttribute
(
"light"
)
if
exists
{
if
value
==
"ON"
{
light
:=
dev
.
GetAttribute
(
"light"
)
light
.
SetValue
(
true
)
if
value
==
"ON"
{
}
else
{
light
.
SetValue
(
true
)
light
.
SetValue
(
false
)
}
else
{
light
.
SetValue
(
false
)
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
z2m.go
+
2
−
12
View file @
28074d42
...
@@ -92,19 +92,9 @@ func (zDev *Z2MDevice) Available() {
...
@@ -92,19 +92,9 @@ func (zDev *Z2MDevice) Available() {
func
(
zDev
*
Z2MDevice
)
Sync
()
{
func
(
zDev
*
Z2MDevice
)
Sync
()
{
client
:=
GetGW
()
.
client
client
:=
GetGW
()
.
client
buf
:=
``
if
token
:=
client
.
Publish
(
zDev
.
GetTopic
()
+
"/dump"
,
0
,
false
,
"{}"
);
token
.
Wait
()
&&
token
.
Error
()
!=
nil
{
for
_
,
expose
:=
range
zDev
.
Definition
.
Exposes
{
if
expose
.
Access
==
1
||
expose
.
Access
==
3
||
expose
.
Access
==
5
||
expose
.
Access
==
7
{
buf
+=
fmt
.
Sprintf
(
`"%s": "",`
,
expose
.
Name
)
}
}
buf
=
strings
.
TrimSuffix
(
buf
,
","
)
buf
=
`{`
+
buf
+
`}`
fmt
.
Println
(
buf
)
if
token
:=
client
.
Publish
(
zDev
.
GetTopic
()
+
"/get"
,
0
,
false
,
buf
);
token
.
Wait
()
&&
token
.
Error
()
!=
nil
{
slog
.
Error
(
"REFRESH Error"
,
":"
,
token
.
Error
())
slog
.
Error
(
"REFRESH Error"
,
":"
,
token
.
Error
())
}
}
}
}
func
(
l
AccessLevel
)
String
()
string
{
func
(
l
AccessLevel
)
String
()
string
{
...
@@ -168,7 +158,7 @@ func jsonParseDevices(jsonData []byte) {
...
@@ -168,7 +158,7 @@ func jsonParseDevices(jsonData []byte) {
newXAALDevices
(
gw
,
&
zDev
)
newXAALDevices
(
gw
,
&
zDev
)
// TODO: filter if device already exists
// TODO: filter if device already exists
gw
.
AddZDevice
(
&
zDev
)
gw
.
AddZDevice
(
&
zDev
)
//
zDev.Sync()
zDev
.
Sync
()
}
}
}
}
...
...
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