Skip to content
Snippets Groups Projects
Commit f2f1b8d2 authored by jkerdreu's avatar jkerdreu
Browse files

This is the end ?

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/branches/0.7@2477 b32b6428-25c9-4566-ad07-03861ab6144f
parent a7a1c52b
Branches
No related tags found
No related merge requests found
......@@ -6,16 +6,51 @@ and RGB lamps. It use the cloud base "Smart Life" mobile application (Android/IO
This protocol isn't really reliable. If you can, avoid the use of Smart Life APP
when this gateway is running. This should be ok, but attributes can be out of
sync. The gateway polls devices state every 30 seconds but due to socket error,
sync. The gateway polls devices state every 45 seconds but due to socket error,
this can be a little longuer.
The pytuya binding version 7.0.5 fixes the issue with version 3.3 devices.
The complete guide to extract keys is there:
- https://github.com/codetheweb/tuyapi/blob/master/docs/SETUP.md
Notes :
pytuya send commmands (including updates) with socket in no-wait mode, and close
it at each request. I have a lot of random connection reset by peer, so I decided
to use tenacity. The main issue is that tuya devices close every connection after
10 seconds, so doing something else isn't really easy.
\ No newline at end of file
The main issue is that tuya devices close every connection after 10 seconds.
Supported devices
=================
The gateway supports: PowerRelays (from 1 to x relais), SmartPlugs (same as relais
but with a single power-meter), lamps and RGB lamps
Configuration samples
=====================
- RGB Lamp / LSC RGB1
[[device_id]]
ip = 192.168.1.x
key = xxxxxxxxxxxxxxxx
type = rgblamp
white_temp = 1800, 2700 # for LSC
white_temp = 3000, 6500 # for Utorch LE7
- Alphawise dumb single outlet
[[device_id]]
ip = 192.168.1.x
key = xxxxxxxxxxxxxxxx
type = powerrelay
- SmartPlug (single outlet) / BW-SHP6
[[device_id]]
ip = 192.168.1.x
key = xxxxxxxxxxxxxxxx
type = smartplug
- SmartPlug (dual outlet) / BW-SHP7
[[device_id]]
ip = 192.168.1.x
key = xxxxxxxxxxxxxxxx
type = smartplug
dps = 1, 2 # <= 2 outlets
pmeter_dps = 18, 19, 20 # <= dps for current / power / voltage
......@@ -18,7 +18,6 @@ logger = logging.getLogger(__name__)
# disable tuyaface debug
#logging.getLogger('tuyaface').setLevel(logging.ERROR)
# number of retry
RETRY_COUNTER=2
......@@ -170,6 +169,7 @@ class TuyaDev:
self.last_update = now()
data=self.status()
if data:
#logger.warning(data)
self.on_status(data)
#========================================================================
......@@ -194,7 +194,7 @@ class TuyaDev:
def set_status(self,data):
data = retry(tuya.set_status,self.tuya_info,data)
if data:
#logger.debug(data)
#logger.warning(data)
self.on_status(data)
return data
......@@ -279,6 +279,15 @@ class RGBLamp(TuyaDev):
dev.methods['toggle'] = self.toggle
self.devices.append(dev)
# setting up white balance min/max
white_temp=self.cfg.get('white_temp',None)
if white_temp:
self.white_min = int(white_temp[0])
self.white_max = int(white_temp[1])
else:
self.white_min = 1500
self.white_max = 6500
def on_status(self,data):
attrs = self.devices[0].attributes
# state
......@@ -299,7 +308,9 @@ class RGBLamp(TuyaDev):
# color_temperature
result = get_dps(data,4)
if result:
attrs['color_temperature'] = result
delta = (self.white_max - self.white_min) / 255.0
value = int(result) * delta + self.white_min
attrs['color_temperature'] = round(value)
# color value (hsv)
result = get_dps(data,5)
if result:
......@@ -308,7 +319,11 @@ class RGBLamp(TuyaDev):
@spawn
def set_color_temperature(self,_color_temperature):
value = int(_color_temperature)
self.set_status({2:'white',4:value})
delta = (self.white_max - self.white_min) / 255.0
target = int((value - self.white_min) / delta)
if target > 255: target = 255
if target < 0: target = 0
self.set_status({2:'white',4:target})
@spawn
def set_brightness(self,_brightness,_smooth=0):
......
......@@ -46,9 +46,9 @@ class GW:
gw.attributes['embedded'] = []
self.gw = gw
devices = self.cfg.get('devices',[])
for d in devices:
cfg = devices.get(d,{})
devs = self.cfg.get('devices',[])
for d in devs:
cfg = devs.get(d,{})
tmp = cfg.get('type','PowerRelay')
dev_type = CFG_MAP.get(tmp,None)
if dev_type:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment