Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CyanLight
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
fxk8y
CyanLight
Commits
ee4dcff2
Commit
ee4dcff2
authored
3 years ago
by
fxk8y
Browse files
Options
Downloads
Patches
Plain Diff
Using JSON instead of YAML as the ESPs only do JSON serialization atm
parent
53e6fc37
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
devtools/mqtt/FakeQthingDevice.py
+21
-10
21 additions, 10 deletions
devtools/mqtt/FakeQthingDevice.py
devtools/mqtt/MMQTT.py
+4
-2
4 additions, 2 deletions
devtools/mqtt/MMQTT.py
with
25 additions
and
12 deletions
devtools/mqtt/FakeQthingDevice.py
+
21
−
10
View file @
ee4dcff2
...
...
@@ -3,7 +3,6 @@
import
time
import
random
from
xmlrpc.client
import
Boolean
from
MMQTT
import
MMQTT
...
...
@@ -52,7 +51,7 @@ class PublishAction(Action):
class
OnlineStatusAction
:
def
__init__
(
self
,
online
:
B
ool
ean
):
def
__init__
(
self
,
online
:
b
ool
):
self
.
online
=
online
def
execute
(
self
,
dev
:
Device
)
->
None
:
...
...
@@ -84,7 +83,7 @@ class ListenerAction:
class
MetricsAction
:
def
__init__
(
self
,
nameSpace
:
str
=
'
CyanLight
'
,
reset
:
int
=
None
,
uptime
:
int
=
None
,
lifetime
:
int
=
None
,
**
metrics
):
def
__init__
(
self
,
nameSpace
:
str
=
'
CyanLight
'
,
reset
:
int
=
(
1
,
1337
)
,
uptime
:
int
=
(
1
,
1e6
)
,
lifetime
:
int
=
None
,
birth
:
int
=
(
1e9
,
time
.
time
()),
**
metrics
):
'''
Setting a metric to None means it gets randomized every action
The predefined metrics are mandatory, but may be overwritten through **kwargs
...
...
@@ -93,6 +92,7 @@ class MetricsAction:
self
.
nameSpace
=
nameSpace
self
.
metrics
=
{}
self
.
metrics
[
'
birth
'
]
=
birth
self
.
metrics
[
'
reset
'
]
=
reset
self
.
metrics
[
'
uptime
'
]
=
uptime
self
.
metrics
[
'
lifetime
'
]
=
lifetime
...
...
@@ -108,7 +108,7 @@ class MetricsAction:
if
v
is
None
:
metrics
[
k
]
=
random
.
randrange
(
1
,
2
**
32
)
elif
issubclass
(
type
(
v
),
tuple
)
and
len
(
v
)
>=
2
and
v
[
0
]
<
v
[
1
]:
metrics
[
k
]
=
random
.
randrange
(
v
[
0
],
v
[
1
])
metrics
[
k
]
=
random
.
randrange
(
int
(
v
[
0
]
)
,
int
(
v
[
1
])
)
else
:
metrics
[
k
]
=
v
...
...
@@ -126,12 +126,23 @@ if __name__ == '__main__':
on
=
OnlineStatusAction
(
True
)
off
=
OnlineStatusAction
(
False
)
pause
=
SleepAction
()
p1
=
SleepAction
(
1
)
p3
=
SleepAction
(
3
)
p5
=
SleepAction
(
5
)
# p10 = SleepAction(10)
listener
=
ListenerAction
()
metrics
=
MetricsAction
()
dev
=
Device
(
'
ringclock
'
,
mqtt
)
on
.
execute
(
dev
)
pause
.
execute
(
dev
)
off
.
execute
(
dev
)
time
.
sleep
(
0.5
)
while
True
:
on
.
execute
(
dev
)
p1
.
execute
(
dev
)
listener
.
execute
(
dev
)
p1
.
execute
(
dev
)
for
_
in
range
(
10
):
metrics
.
execute
(
dev
)
p3
.
execute
(
dev
)
p3
.
execute
(
dev
)
off
.
execute
(
dev
)
p5
.
execute
(
dev
)
This diff is collapsed.
Click to expand it.
devtools/mqtt/MMQTT.py
+
4
−
2
View file @
ee4dcff2
import
yaml
# import yaml
import
json
import
time
import
random
import
paho.mqtt.client
as
mqtt
...
...
@@ -50,7 +51,8 @@ class MMQTT:
elif
issubclass
(
payloadType
,
(
bool
,
int
,
float
,
complex
)):
pl
=
str
(
payload
).
encode
(
'
utf-8
'
)
elif
issubclass
(
payloadType
,
(
list
,
set
,
dict
)):
pl
=
yaml
.
dump
(
payload
,
default_flow_style
=
not
prettyPrintYAML
).
encode
(
'
utf-8
'
)
pl
=
json
.
dumps
(
payload
).
encode
(
'
utf-8
'
)
# pl = yaml.dump(payload, default_flow_style=not prettyPrintYAML).encode('utf-8')
else
:
pl
=
payload
...
...
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