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
43f96e20
Commit
43f96e20
authored
4 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Same API for all XAALDevice
Merged the API for all devices
parent
5c360566
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
+34
-34
34 additions, 34 deletions
xaal.go
z2m.go
+9
-6
9 additions, 6 deletions
z2m.go
with
43 additions
and
40 deletions
xaal.go
+
34
−
34
View file @
43f96e20
...
...
@@ -11,8 +11,11 @@ import (
"gitlab.imt-atlantique.fr/xaal/code/go/core/xaal"
)
// This is a xaal.Device w/ Z2MDevice and Expose
type
XAALDevice
struct
{
*
xaal
.
Device
Z2MDevice
*
Z2MDevice
Expose
*
Expose
}
type
Contact
struct
{
...
...
@@ -37,8 +40,6 @@ type Battery struct {
type
PowerRelay
struct
{
XAALDevice
Expose
Expose
Z2MDevice
Z2MDevice
}
type
PowerMeter
struct
{
...
...
@@ -47,12 +48,10 @@ type PowerMeter struct {
type
Lamp
struct
{
XAALDevice
Z2MDevice
Z2MDevice
}
type
ButtonRemote
struct
{
XAALDevice
Z2MDevice
Z2MDevice
}
type
XAALDeviceInterface
interface
{
...
...
@@ -60,7 +59,8 @@ type XAALDeviceInterface interface {
getXAALDevice
()
*
xaal
.
Device
}
func
(
dev
*
XAALDevice
)
setup
(
zDev
*
Z2MDevice
)
{
func
(
dev
*
XAALDevice
)
setup
()
{
zDev
:=
dev
.
Z2MDevice
dev
.
VendorID
=
zDev
.
Definition
.
Vendor
dev
.
ProductID
=
zDev
.
Definition
.
Model
dev
.
HWID
=
zDev
.
IeeeAddress
...
...
@@ -75,9 +75,9 @@ func (dev *XAALDevice) getXAALDevice() *xaal.Device {
// =============================================================================
// Contact
// =============================================================================
func
NewContact
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
)
XAALDeviceInterface
{
dev
:=
&
Contact
{
XAALDevice
{
schemas
.
NewContact
(
addr
)}}
dev
.
setup
(
zDev
)
func
NewContact
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
Contact
{
XAALDevice
{
schemas
.
NewContact
(
addr
)
,
zDev
,
exp
}}
dev
.
setup
()
return
dev
}
...
...
@@ -91,9 +91,9 @@ func (dev *Contact) update(payload map[string]interface{}) {
// =============================================================================
// Thermometer
// =============================================================================
func
NewThermometer
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
)
XAALDeviceInterface
{
dev
:=
&
Thermometer
{
XAALDevice
{
schemas
.
NewThermometer
(
addr
)}}
dev
.
setup
(
zDev
)
func
NewThermometer
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
Thermometer
{
XAALDevice
{
schemas
.
NewThermometer
(
addr
)
,
zDev
,
exp
}}
dev
.
setup
()
return
dev
}
...
...
@@ -107,9 +107,9 @@ func (dev *Thermometer) update(payload map[string]interface{}) {
// =============================================================================
// Hygrometer
// =============================================================================
func
NewHygrometer
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
)
XAALDeviceInterface
{
dev
:=
&
Hygrometer
{
XAALDevice
{
schemas
.
NewHygrometer
(
addr
)}}
dev
.
setup
(
zDev
)
func
NewHygrometer
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
Hygrometer
{
XAALDevice
{
schemas
.
NewHygrometer
(
addr
)
,
zDev
,
exp
}}
dev
.
setup
()
return
dev
}
...
...
@@ -123,9 +123,9 @@ func (dev *Hygrometer) update(payload map[string]interface{}) {
// =============================================================================
// LinkQuality
// =============================================================================
func
NewLinkQuality
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
)
XAALDeviceInterface
{
dev
:=
&
LinkQuality
{
XAALDevice
{
schemas
.
NewLinkquality
(
addr
)}}
dev
.
setup
(
zDev
)
func
NewLinkQuality
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
LinkQuality
{
XAALDevice
{
schemas
.
NewLinkquality
(
addr
)
,
zDev
,
exp
}}
dev
.
setup
()
dev
.
RemoveAttribute
(
"devices"
)
dev
.
UnsupportedAttributes
=
[]
string
{
"devices"
}
return
dev
...
...
@@ -142,9 +142,9 @@ func (dev *LinkQuality) update(payload map[string]interface{}) {
// =============================================================================
// Battery
// =============================================================================
func
NewBattery
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
)
XAALDeviceInterface
{
dev
:=
&
Battery
{
XAALDevice
{
schemas
.
NewBattery
(
addr
)}}
dev
.
setup
(
zDev
)
func
NewBattery
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
Battery
{
XAALDevice
{
schemas
.
NewBattery
(
addr
)
,
zDev
,
exp
}}
dev
.
setup
()
dev
.
RemoveAttribute
(
"devices"
)
dev
.
UnsupportedAttributes
=
[]
string
{
"devices"
}
return
dev
...
...
@@ -161,11 +161,11 @@ func (dev *Battery) update(payload map[string]interface{}) {
// PowerRelay
// =============================================================================
func
NewPowerRelay
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
PowerRelay
{
XAALDevice
{
schemas
.
NewPowerrelayToggle
(
addr
)
},
*
exp
,
*
zDev
}
dev
:=
&
PowerRelay
{
XAALDevice
{
schemas
.
NewPowerrelayToggle
(
addr
),
zDev
,
exp
}
}
dev
.
SetMethod
(
"turn_on"
,
dev
.
On
)
dev
.
SetMethod
(
"turn_off"
,
dev
.
Off
)
dev
.
SetMethod
(
"toggle"
,
dev
.
Toggle
)
dev
.
setup
(
zDev
)
dev
.
setup
()
return
dev
}
...
...
@@ -208,9 +208,9 @@ func (dev *PowerRelay) Toggle(xaal.MessageBody) *xaal.MessageBody {
// =============================================================================
// PowerMeter
// =============================================================================
func
NewPowerMeter
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
)
XAALDeviceInterface
{
dev
:=
&
PowerMeter
{
XAALDevice
{
schemas
.
NewPowermeter
(
addr
)}}
dev
.
setup
(
zDev
)
func
NewPowerMeter
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
PowerMeter
{
XAALDevice
{
schemas
.
NewPowermeter
(
addr
)
,
zDev
,
exp
}}
dev
.
setup
()
dev
.
RemoveAttribute
(
"devices"
)
dev
.
UnsupportedAttributes
=
[]
string
{
"devices"
}
return
dev
...
...
@@ -232,23 +232,23 @@ func (dev *PowerMeter) update(payload map[string]interface{}) {
// =============================================================================
// Lamp
// =============================================================================
func
NewLamp
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
ose
*
Expose
)
XAALDeviceInterface
{
func
NewLamp
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
// This is the default lamp device, we will change it's devType if needed
dev
:=
&
Lamp
{
XAALDevice
{
schemas
.
NewLamp
(
addr
)
}
,
*
zDev
}
dev
:=
&
Lamp
{
XAALDevice
{
schemas
.
NewLamp
(
addr
),
zDev
,
exp
}
}
dev
.
SetMethod
(
"turn_on"
,
dev
.
turnOn
)
dev
.
SetMethod
(
"turn_off"
,
dev
.
turnOff
)
dev
.
SetMethod
(
"toggle"
,
dev
.
toggle
)
if
exp
ose
.
GetFeature
(
"brightness"
)
!=
nil
{
if
exp
.
GetFeature
(
"brightness"
)
!=
nil
{
dev
.
DevType
=
"lamp.dimmer"
dev
.
AddAttribute
(
"brightness"
,
0
)
dev
.
AddMethod
(
"set_brightness"
,
dev
.
setBrightness
)
}
if
exp
ose
.
GetFeature
(
"color_temp"
)
!=
nil
{
if
exp
.
GetFeature
(
"color_temp"
)
!=
nil
{
dev
.
DevType
=
"lamp.dimmer"
dev
.
AddAttribute
(
"white_temperature"
,
0
)
dev
.
AddMethod
(
"set_white_temperature"
,
dev
.
setWhiteTemperature
)
}
if
exp
ose
.
GetFeature
(
"color_xy"
)
!=
nil
{
if
exp
.
GetFeature
(
"color_xy"
)
!=
nil
{
dev
.
DevType
=
"lamp.color"
dev
.
AddAttribute
(
"hsv"
,
[]
float64
{
0
,
0
,
0
})
dev
.
AddAttribute
(
"mode"
,
nil
)
...
...
@@ -256,7 +256,7 @@ func NewLamp(addr uuid.UUID, zDev *Z2MDevice, expose *Expose) XAALDeviceInterfac
dev
.
AddMethod
(
"set_hsv"
,
dev
.
setHSV
)
dev
.
AddMethod
(
"set_mode"
,
dev
.
setMode
)
}
dev
.
setup
(
zDev
)
dev
.
setup
()
return
dev
}
...
...
@@ -410,9 +410,9 @@ func (dev *Lamp) setMode(body xaal.MessageBody) *xaal.MessageBody {
// =============================================================================
// NetButtonRemote
// =============================================================================
func
NewButtonRemote
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
)
XAALDeviceInterface
{
dev
:=
&
ButtonRemote
{
XAALDevice
{
schemas
.
NewButtonRemote
(
addr
)
}
,
*
zDev
}
dev
.
setup
(
zDev
)
func
NewButtonRemote
(
addr
uuid
.
UUID
,
zDev
*
Z2MDevice
,
exp
*
Expose
)
XAALDeviceInterface
{
dev
:=
&
ButtonRemote
{
XAALDevice
{
schemas
.
NewButtonRemote
(
addr
),
zDev
,
exp
}
}
dev
.
setup
()
dev
.
SetMethod
(
"get_buttons"
,
dev
.
GetButtons
)
return
dev
}
...
...
This diff is collapsed.
Click to expand it.
z2m.go
+
9
−
6
View file @
43f96e20
...
...
@@ -111,7 +111,7 @@ func (zDev *Z2MDevice) setupXAALDevices(gw *Gateway) {
grpAdd
,
_
:=
baseAddr
.
Add
(
int64
(
0xff
))
var
dev
XAALDeviceInterface
deviceMap
:=
map
[
string
]
func
(
uuid
.
UUID
,
*
Z2MDevice
)
XAALDeviceInterface
{
deviceMap
:=
map
[
string
]
func
(
uuid
.
UUID
,
*
Z2MDevice
,
*
Expose
)
XAALDeviceInterface
{
"contact"
:
NewContact
,
"temperature"
:
NewThermometer
,
"humidity"
:
NewHygrometer
,
...
...
@@ -119,14 +119,17 @@ func (zDev *Z2MDevice) setupXAALDevices(gw *Gateway) {
"battery"
:
NewBattery
,
"power"
:
NewPowerMeter
,
"action"
:
NewButtonRemote
,
"switch"
:
NewPowerRelay
,
"light"
:
NewLamp
,
}
// Search a matching expose name
if
createFunc
,
ok
:=
deviceMap
[
expose
.
Name
];
ok
{
dev
=
createFunc
(
addr
,
zDev
)
}
else
if
expose
.
Type
==
"switch"
{
dev
=
NewPowerRelay
(
addr
,
zDev
,
&
expose
)
}
else
if
expose
.
Type
==
"light"
{
dev
=
NewLamp
(
addr
,
zDev
,
&
expose
)
dev
=
createFunc
(
addr
,
zDev
,
&
expose
)
}
// Search a matching
expose
type
if
createFunc
,
ok
:=
deviceMap
[
zDev
.
Type
];
ok
{
dev
=
createFunc
(
addr
,
zDev
,
&
expose
)
}
if
dev
!=
nil
{
...
...
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