Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
shared-libs
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
Pi-Lab
shared-libs
Commits
60e4e830
Commit
60e4e830
authored
2 years ago
by
istmxrein
Browse files
Options
Downloads
Patches
Plain Diff
add power consume manager & bump to 1.6.0
parent
0cf09590
Branches
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
pilab/events/power.py
+47
-0
47 additions, 0 deletions
pilab/events/power.py
setup.py
+1
-1
1 addition, 1 deletion
setup.py
with
48 additions
and
1 deletion
pilab/events/power.py
+
47
−
0
View file @
60e4e830
import
collections
import
functools
import
functools
import
json
import
json
import
logging
import
logging
...
@@ -319,3 +320,49 @@ class PowerConsumer(threading.Thread):
...
@@ -319,3 +320,49 @@ class PowerConsumer(threading.Thread):
else
:
else
:
self
.
_connection
.
ioloop
.
stop
()
self
.
_connection
.
ioloop
.
stop
()
logger
.
info
(
'
Stopped
'
)
logger
.
info
(
'
Stopped
'
)
state
:
Dict
[
str
,
State
]
=
{}
custom_callback
:
Callable
=
None
pi_consumer
:
PowerConsumer
=
None
controller_consumer
:
PowerConsumer
=
None
switch_consumer
:
PowerConsumer
=
None
def
event_callback
(
event
:
Event
):
logger
.
info
(
f
"
Received Power event:
{
event
}
"
)
if
custom_callback
:
custom_callback
(
event
)
state
[
event
.
mac
]
=
event
.
state
def
run_restart_consumer
(
macs
:
List
[
str
],
_type
:
Type
,
callback
:
Callable
=
None
):
global
custom_callback
,
pi_consumer
,
controller_consumer
,
switch_consumer
custom_callback
=
callback
def
restart_consumer
(
consumer
:
PowerConsumer
):
if
not
consumer
:
consumer
=
PowerConsumer
(
queues
=
macs
,
callback
=
event_callback
,
type
=
_type
)
consumer
.
start
()
logger
.
info
(
f
'
Restart power consumer for type
{
_type
.
value
}
'
)
return
consumer
elif
collections
.
Counter
(
consumer
.
queues
)
!=
collections
.
Counter
(
macs
):
consumer
.
stop
()
consumer
.
join
()
consumer
=
PowerConsumer
(
queues
=
macs
,
callback
=
event_callback
,
type
=
_type
)
consumer
.
start
()
logger
.
info
(
f
'
Restart power consumer for type
{
_type
.
value
}
'
)
return
consumer
else
:
return
consumer
match
_type
:
case
Type
.
pi
:
pi_consumer
=
restart_consumer
(
pi_consumer
)
case
Type
.
controller
:
controller_consumer
=
restart_consumer
(
controller_consumer
)
case
Type
.
switch
:
switch_consumer
=
restart_consumer
(
switch_consumer
)
case
_
:
raise
ValueError
(
"
Type is not known
"
)
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
60e4e830
...
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
...
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup
(
setup
(
name
=
'
pilab
'
,
name
=
'
pilab
'
,
version
=
'
1.
5.9
'
,
version
=
'
1.
6.0
'
,
description
=
'
Shared-Libs for the pi-lab microservices
'
,
description
=
'
Shared-Libs for the pi-lab microservices
'
,
url
=
'
https://code.fbi.h-da.de/api/v4/projects/27896/packages/pypi/pilab
'
,
url
=
'
https://code.fbi.h-da.de/api/v4/projects/27896/packages/pypi/pilab
'
,
author
=
'
Max Reinheimer
'
,
author
=
'
Max Reinheimer
'
,
...
...
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