Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Python
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xAAL
Code
Python
Commits
25e04b88
Commit
25e04b88
authored
3 months ago
by
KERDREUX Jerome
Browse files
Options
Downloads
Patches
Plain Diff
Black before switching to another lib
parent
4347e4fd
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
devices/protocols/Tuya/xaal/tuya/tuyaclient.py
+65
-60
65 additions, 60 deletions
devices/protocols/Tuya/xaal/tuya/tuyaclient.py
with
65 additions
and
60 deletions
devices/protocols/Tuya/xaal/tuya/tuyaclient.py
+
65
−
60
View file @
25e04b88
from
gevent
import
monkey
;
monkey
.
patch_socket
();
from
gevent
import
monkey
monkey
.
patch_socket
()
import
gevent
from
decorator
import
decorator
...
...
@@ -14,12 +16,15 @@ import enum
import
logging
logger
=
logging
.
getLogger
(
__name__
)
logging
.
getLogger
(
'
tuyaface
'
).
setLevel
(
'
INFO
'
)
# logging.getLogger('tuyaface').setLevel('INFO')
logging
.
getLogger
(
'
tuyaface
'
).
setLevel
(
'
DEBUG
'
)
HEART_BEAT_DELAY
=
7
@decorator
def
spawn
(
func
,
*
args
,
**
kwargs
):
gevent
.
spawn
(
func
,
*
args
,
**
kwargs
)
...
...
@@ -28,6 +33,7 @@ def spawn(func,*args,**kwargs):
def
now
():
return
time
.
time
()
class
Event
(
enum
.
Enum
):
DISCONNECTED
=
0
CONNECTED
=
1
...
...
@@ -92,6 +98,8 @@ class TuyaClient(object):
def
receive
(
self
):
try
:
data
=
self
.
sock
.
recv
(
4096
)
if
data
:
logger
.
debug
(
f
"
Received from
{
self
.
ip
}
:
{
data
}
"
)
result
=
list
(
tuyaface
.
_process_raw_reply
(
self
.
device
,
data
))
self
.
last_recv
=
now
()
return
result
...
...
@@ -104,7 +112,6 @@ class TuyaClient(object):
self
.
pubish
(
Event
.
DISCONNECTED
)
self
.
connected
=
False
# ========================================================================
# DPS Handling / parse / query / post
# ========================================================================
...
...
@@ -205,7 +212,6 @@ class TuyaClient(object):
gevent
.
sleep
(
0.1
)
def
color_to_hex
(
hsv
):
"""
Converts the hsv list in a hexvalue.
...
...
@@ -240,6 +246,7 @@ def color_to_hex(hsv):
hexvalue
=
hexvalue
+
"
00
"
+
hexvalue_hsv
return
hexvalue
def
hexvalue_to_hsv
(
hexvalue
):
"""
Converts the hexvalue used by tuya for colour representation into
...
...
@@ -254,12 +261,11 @@ def hexvalue_to_hsv(hexvalue):
return
(
h
,
s
,
v
)
def
evt_test
(
ev_type
,
ev_data
):
if
ev_type
!=
Event
.
PONG
:
print
(
f
"
New event
{
Event
(
ev_type
)
}
{
ev_data
}
"
)
def
launch
(
dev
):
c
=
TuyaClient
(
dev
)
c
.
start
()
...
...
@@ -269,6 +275,7 @@ def launch(dev):
def
test
():
import
coloredlogs
coloredlogs
.
install
(
'
DEBUG
'
)
from
gevent.backdoor
import
BackdoorServer
...
...
@@ -308,5 +315,3 @@ def test():
if
__name__
==
'
__main__
'
:
test
()
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
sign in
to comment