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
23359e27
Commit
23359e27
authored
2 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Cleanup API
parent
b2667ed2
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
gateway.go
+2
-2
2 additions, 2 deletions
gateway.go
utils.go
+1
-1
1 addition, 1 deletion
utils.go
xaal.go
+13
-13
13 additions, 13 deletions
xaal.go
with
16 additions
and
16 deletions
gateway.go
+
2
−
2
View file @
23359e27
...
...
@@ -30,7 +30,7 @@ func (gw *Gateway) GetZDevice(name string) *Z2MDevice {
func
(
gw
*
Gateway
)
AddZDevice
(
zDev
*
Z2MDevice
)
{
for
_
,
xDev
:=
range
zDev
.
XAALDevices
{
dev
:=
xDev
.
G
etXAALDevice
()
dev
:=
xDev
.
g
etXAALDevice
()
slog
.
Debug
(
"Adding device"
,
"dev"
,
dev
.
String
())
gw
.
Engine
.
AddDevice
(
dev
)
}
...
...
@@ -40,7 +40,7 @@ func (gw *Gateway) AddZDevice(zDev *Z2MDevice) {
func
(
gw
*
Gateway
)
RemoveZDevice
(
zDev
*
Z2MDevice
)
{
for
_
,
xDev
:=
range
zDev
.
XAALDevices
{
dev
:=
xDev
.
G
etXAALDevice
()
dev
:=
xDev
.
g
etXAALDevice
()
slog
.
Debug
(
"Removing device"
,
"dev"
,
dev
.
String
())
gw
.
Engine
.
RemoveDevice
(
dev
)
}
...
...
This diff is collapsed.
Click to expand it.
utils.go
+
1
−
1
View file @
23359e27
...
...
@@ -118,7 +118,7 @@ func convertMired(value int) int {
return
1e6
/
int
(
value
)
}
func
convertToFloat
64
(
value
interface
{})
(
float64
,
error
)
{
func
convertToFloat
(
value
interface
{})
(
float64
,
error
)
{
switch
v
:=
value
.
(
type
)
{
case
float32
:
return
float64
(
v
),
nil
...
...
This diff is collapsed.
Click to expand it.
xaal.go
+
13
−
13
View file @
23359e27
...
...
@@ -114,7 +114,7 @@ func NewThermometer(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInte
}
func
(
dev
*
Thermometer
)
update
(
payload
map
[
string
]
interface
{})
{
value
,
err
:=
convertToFloat
64
(
payload
[
dev
.
Expose
.
Name
])
value
,
err
:=
convertToFloat
(
payload
[
dev
.
Expose
.
Name
])
if
err
==
nil
{
dev
.
GetAttribute
(
"temperature"
)
.
SetValue
(
value
)
}
...
...
@@ -128,7 +128,7 @@ func NewHygrometer(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInter
}
func
(
dev
*
Hygrometer
)
update
(
payload
map
[
string
]
interface
{})
{
value
,
err
:=
convertToFloat
64
(
payload
[
dev
.
Expose
.
Name
])
value
,
err
:=
convertToFloat
(
payload
[
dev
.
Expose
.
Name
])
if
err
==
nil
{
dev
.
GetAttribute
(
"humidity"
)
.
SetValue
(
value
)
}
...
...
@@ -167,7 +167,7 @@ func NewBattery(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInterfac
}
func
(
dev
*
Battery
)
update
(
payload
map
[
string
]
interface
{})
{
value
,
err
:=
convertToFloat
64
(
payload
[
dev
.
Expose
.
Name
])
value
,
err
:=
convertToFloat
(
payload
[
dev
.
Expose
.
Name
])
if
err
==
nil
{
dev
.
GetAttribute
(
"level"
)
.
SetValue
(
value
)
}
...
...
@@ -232,12 +232,12 @@ func NewPowerMeter(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInter
func
(
dev
*
PowerMeter
)
update
(
payload
map
[
string
]
interface
{})
{
// power
value
,
err
:=
convertToFloat
64
(
payload
[
dev
.
Expose
.
Name
])
value
,
err
:=
convertToFloat
(
payload
[
dev
.
Expose
.
Name
])
if
err
==
nil
{
dev
.
GetAttribute
(
"power"
)
.
SetValue
(
value
)
}
// energy
value
,
err
=
convertToFloat
64
(
payload
[
"energy"
])
value
,
err
=
convertToFloat
(
payload
[
"energy"
])
if
err
==
nil
{
dev
.
GetAttribute
(
"energy"
)
.
SetValue
(
value
)
}
...
...
@@ -333,9 +333,9 @@ func (dev *Lamp) update(payload map[string]interface{}) {
if
dev
.
getMode
()
==
"color"
{
color
,
exists
:=
payload
[
"color"
]
.
(
map
[
string
]
interface
{})
if
exists
{
x
,
_
:=
convertToFloat
64
(
color
[
"x"
])
y
,
_
:=
convertToFloat
64
(
color
[
"y"
])
brigthness
,
_
:=
convertToFloat
64
(
payload
[
"brightness"
])
x
,
_
:=
convertToFloat
(
color
[
"x"
])
y
,
_
:=
convertToFloat
(
color
[
"y"
])
brigthness
,
_
:=
convertToFloat
(
payload
[
"brightness"
])
value
:=
xyToColor
(
x
,
y
,
brigthness
)
slog
.
Debug
(
"color"
,
"color"
,
value
.
Hex
(),
"x"
,
x
,
"y"
,
y
,
"tmp"
,
brigthness
)
hue
,
sat
,
val
:=
value
.
Hsv
()
...
...
@@ -387,9 +387,9 @@ func (dev *Lamp) setWhiteTemperature(body xaal.MessageBody) *xaal.MessageBody {
func
(
dev
*
Lamp
)
setHSV
(
body
xaal
.
MessageBody
)
*
xaal
.
MessageBody
{
value
,
exist
:=
body
[
"hsv"
]
.
([]
interface
{})
if
exist
{
hue
,
_
:=
convertToFloat
64
(
value
[
0
])
sat
,
_
:=
convertToFloat
64
(
value
[
1
])
val
,
_
:=
convertToFloat
64
(
value
[
2
])
hue
,
_
:=
convertToFloat
(
value
[
0
])
sat
,
_
:=
convertToFloat
(
value
[
1
])
val
,
_
:=
convertToFloat
(
value
[
2
])
color
:=
colorful
.
Hsv
(
hue
,
sat
,
val
)
slog
.
Debug
(
"setHSV"
,
"color"
,
color
.
Hex
(),
"hue"
,
hue
,
"sat"
,
sat
,
"val"
,
val
)
dev
.
Z2MDevice
.
Set
(
fmt
.
Sprintf
(
`{"color": { "hex": "%s" }}`
,
color
.
Hex
()))
...
...
@@ -494,7 +494,7 @@ func NewVoltMeter(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInterf
}
func
(
dev
*
VoltMeter
)
update
(
payload
map
[
string
]
interface
{})
{
value
,
err
:=
convertToFloat
64
(
payload
[
dev
.
Expose
.
Name
])
value
,
err
:=
convertToFloat
(
payload
[
dev
.
Expose
.
Name
])
if
err
==
nil
{
dev
.
GetAttribute
(
"voltage"
)
.
SetValue
(
value
)
}
...
...
@@ -511,7 +511,7 @@ func NewAmpMeter(addr uuid.UUID, zDev *Z2MDevice, exp *Expose) XAALDeviceInterfa
}
func
(
dev
*
AmpMeter
)
update
(
payload
map
[
string
]
interface
{})
{
value
,
err
:=
convertToFloat
64
(
payload
[
dev
.
Expose
.
Name
])
value
,
err
:=
convertToFloat
(
payload
[
dev
.
Expose
.
Name
])
if
err
==
nil
{
dev
.
GetAttribute
(
"current"
)
.
SetValue
(
value
)
}
...
...
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