From 44f90d4c667ecd25b1fa37d060cbbeb9e571520e Mon Sep 17 00:00:00 2001 From: g-kiss <70820303+g-kiss@users.noreply.github.com> Date: Sat, 5 Sep 2020 22:17:05 +0200 Subject: [PATCH 1/7] Add files via upload --- pyShelly/switch.py | 111 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/pyShelly/switch.py b/pyShelly/switch.py index d7a617b..e064aac 100644 --- a/pyShelly/switch.py +++ b/pyShelly/switch.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +from threading import Timer + from .device import Device from .utils import notNone from threading import Timer @@ -40,8 +42,116 @@ def __init__(self, block, channel, self.battery_bug_fix = False self.hold_delay = None #bug fix + self.kg_last_event = "" + self.kg_last_event_cnt = None + self.kg_last_state = None + self.kg_click_count = 0 + self.kg_click_error = False + self.kg_click_timer = None + self.kg_send_event_events = None + self.kg_send_event_click_count = None + self.kg_start_state = None + + def kg_send_event(self): + if self.kg_click_error: + self.kg_click_error = False + self.kg_last_event = "" + self.kg_click_count = 0 + else: +# LOGGER.warning(self.kg_last_event) +# LOGGER.warning(self.kg_click_count) + + self.kg_send_event_events = self.kg_last_event + self.kg_send_event_click_count = self.kg_click_count + + self.kg_last_event = "" + self.kg_click_count = 0 + + self.raise_updated(True) + + def update_coap(self, payload): """Get the power""" +# Start pos Action CoAP +# ----------------------------------------------------------------------------------------------------------- +# 0 [0,2101,0],[0,2102,"L"],[0,2103,42] +# 1 Short click [0,2101,0],[0,2102,"S"],[0,2103,43] * +# +# 0 [0,2101,0],[0,2102,"S"],[0,2103,43] +# 1 Normal click [0,2101,1],[0,2102,"S"],[0,2103,43] +# [0,2101,0],[0,2102,"S"],[0,2103,44] * +# +# 0 [0,2101,0],[0,2102,"S"],[0,2103,45] +# 2 Short click [0,2101,0],[0,2102,"S"],[0,2103,47] ** +# +# 0 [0,2101,0],[0,2102,"L"],[0,2103,461] +# 1 Long click [0,2101,1],[0,2102,"L"],[0,2103,461] +# [0,2101,1],[0,2102,"L"],[0,2103,462] * +# [0,2101,0],[0,2102,"L"],[0,2103,462] +# +# 0 [0,2101,0],[0,2102,"S"],[0,2103,67] +# 1 Long click [0,2101,1],[0,2102,"S"],[0,2103,67] +# [0,2101,0],[0,2102,"L"],[0,2103,68] * +# +# 1 [0,2101,1],[0,2102,"L"],[0,2103,74] // Ez 0 clicket ad +# 1 Short click [0,2101,1],[0,2102,"L"],[0,2103,74] +# [0,2101,1],[0,2102,"L"],[0,2103,75] * +# +# 1 [0,2101,1],[0,2102,"L"],[0,2103,466] +# 1 Normal click [0,2101,0],[0,2102,"L"],[0,2103,466] +# [0,2101,1],[0,2102,"L"],[0,2103,466] +# [0,2101,1],[0,2102,"L"],[0,2103,467] * + + if not self.kg_click_timer is None: + self.kg_click_timer.cancel() + + kg_curr_state = self.coap_get(payload, self._position) + kg_curr_event = self.coap_get(payload, self._event_pos) + kg_curr_event_cnt = self.coap_get(payload, self._event_cnt_pos) + if not kg_curr_event_cnt is None: + if not self.kg_last_event_cnt is None and not self.kg_last_state is None: + if kg_curr_event_cnt != self.kg_last_event_cnt: +# if kg_curr_event_cnt - self.kg_last_event_cnt != 1: +# self.kg_click_error = True + + if kg_curr_event == "S": + if self.kg_last_state == 1: + self.kg_click_count += 1 + else: + self.kg_click_count += 2 + if kg_curr_state == 1: + self.kg_click_count += 1 + + if kg_curr_event_cnt - self.kg_last_event_cnt > 1: + self.kg_click_count += kg_curr_event_cnt - self.kg_last_event_cnt - 1 + kg_curr_event = "S"*(kg_curr_event_cnt - self.kg_last_event_cnt) + + if kg_curr_event == "L": + if kg_curr_state != self.kg_last_state: + self.kg_click_count += 1 + if self.kg_click_count == 0: + self.kg_click_count += 2 +# if kg_curr_state == 1 and self.kg_last_state == 1: +# self.kg_click_count += 2 + + self.kg_last_event += kg_curr_event + self.kg_click_timer = Timer(0.7, self.kg_send_event) + self.kg_click_timer.start() + + if kg_curr_event_cnt == self.kg_last_event_cnt and kg_curr_state != self.kg_last_state: + self.kg_click_count += 1 + self.kg_click_timer = Timer(0.7, self.kg_send_event) + self.kg_click_timer.start() + + self.kg_last_state = kg_curr_state + self.kg_last_event_cnt = kg_curr_event_cnt + + + + + + + state = self.coap_get(payload, self._position) event_cnt = self.coap_get(payload, self._event_cnt_pos) self.battery_bug_fix = (self.coap_get(payload, [3112]) == 0 and event_cnt == 1) @@ -65,6 +175,7 @@ def update_coap(self, payload): self._update(SRC_COAP, state, {'last_event' : self.last_event, 'event_cnt' : self.event_cnt}) + def update_status_information(self, status): """Update the status information.""" new_state = None From 292cac1f4979d80a483f12b56f5f310627abd9d0 Mon Sep 17 00:00:00 2001 From: g-kiss <70820303+g-kiss@users.noreply.github.com> Date: Mon, 7 Sep 2020 13:33:16 +0200 Subject: [PATCH 2/7] Update switch.py --- pyShelly/switch.py | 50 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/pyShelly/switch.py b/pyShelly/switch.py index e064aac..7168fba 100644 --- a/pyShelly/switch.py +++ b/pyShelly/switch.py @@ -51,6 +51,7 @@ def __init__(self, block, channel, self.kg_send_event_events = None self.kg_send_event_click_count = None self.kg_start_state = None + self.kg_momentary_button = False def kg_send_event(self): if self.kg_click_error: @@ -61,8 +62,12 @@ def kg_send_event(self): # LOGGER.warning(self.kg_last_event) # LOGGER.warning(self.kg_click_count) - self.kg_send_event_events = self.kg_last_event - self.kg_send_event_click_count = self.kg_click_count + if self.kg_momentary_button: + self.kg_send_event_events = self.kg_last_event + self.kg_send_event_click_count = 0 + else: + self.kg_send_event_events = "" + self.kg_send_event_click_count = self.kg_click_count self.kg_last_event = "" self.kg_click_count = 0 @@ -72,17 +77,17 @@ def kg_send_event(self): def update_coap(self, payload): """Get the power""" -# Start pos Action CoAP +# Start state Action CoAP # ----------------------------------------------------------------------------------------------------------- # 0 [0,2101,0],[0,2102,"L"],[0,2103,42] -# 1 Short click [0,2101,0],[0,2102,"S"],[0,2103,43] * +# 1 Fast click [0,2101,0],[0,2102,"S"],[0,2103,43] * # # 0 [0,2101,0],[0,2102,"S"],[0,2103,43] # 1 Normal click [0,2101,1],[0,2102,"S"],[0,2103,43] # [0,2101,0],[0,2102,"S"],[0,2103,44] * # # 0 [0,2101,0],[0,2102,"S"],[0,2103,45] -# 2 Short click [0,2101,0],[0,2102,"S"],[0,2103,47] ** +# 2 Fast click [0,2101,0],[0,2102,"S"],[0,2103,47] ** # # 0 [0,2101,0],[0,2102,"L"],[0,2103,461] # 1 Long click [0,2101,1],[0,2102,"L"],[0,2103,461] @@ -94,7 +99,7 @@ def update_coap(self, payload): # [0,2101,0],[0,2102,"L"],[0,2103,68] * # # 1 [0,2101,1],[0,2102,"L"],[0,2103,74] // Ez 0 clicket ad -# 1 Short click [0,2101,1],[0,2102,"L"],[0,2103,74] +# 1 Fast click [0,2101,1],[0,2102,"L"],[0,2103,74] # [0,2101,1],[0,2102,"L"],[0,2103,75] * # # 1 [0,2101,1],[0,2102,"L"],[0,2103,466] @@ -123,25 +128,40 @@ def update_coap(self, payload): self.kg_click_count += 1 if kg_curr_event_cnt - self.kg_last_event_cnt > 1: - self.kg_click_count += kg_curr_event_cnt - self.kg_last_event_cnt - 1 + self.kg_click_count += (kg_curr_event_cnt - self.kg_last_event_cnt - 1) * 2 kg_curr_event = "S"*(kg_curr_event_cnt - self.kg_last_event_cnt) if kg_curr_event == "L": - if kg_curr_state != self.kg_last_state: - self.kg_click_count += 1 - if self.kg_click_count == 0: - self.kg_click_count += 2 + if self.kg_momentary_button: + if kg_curr_state != self.kg_last_state: + self.kg_click_count += 1 + else: + if kg_curr_state != self.kg_last_state: + self.kg_click_count += 1 + +# if kg_curr_state == self.kg_last_state: +# self.kg_click_count += 2 + + if kg_curr_event_cnt - self.kg_last_event_cnt > 1: + self.kg_click_count += kg_curr_event_cnt - self.kg_last_event_cnt - 1 + +# if self.kg_click_count == 0: +# self.kg_click_count += 2 # if kg_curr_state == 1 and self.kg_last_state == 1: # self.kg_click_count += 2 self.kg_last_event += kg_curr_event - self.kg_click_timer = Timer(0.7, self.kg_send_event) - self.kg_click_timer.start() + + if not self.kg_momentary_button or kg_curr_state == 0: + self.kg_click_timer = Timer(0.7, self.kg_send_event) + self.kg_click_timer.start() if kg_curr_event_cnt == self.kg_last_event_cnt and kg_curr_state != self.kg_last_state: self.kg_click_count += 1 - self.kg_click_timer = Timer(0.7, self.kg_send_event) - self.kg_click_timer.start() + + if not self.kg_momentary_button or kg_curr_state == 0: + self.kg_click_timer = Timer(0.7, self.kg_send_event) + self.kg_click_timer.start() self.kg_last_state = kg_curr_state self.kg_last_event_cnt = kg_curr_event_cnt From 8f83e971b517f87b486fe00683120bdfdf504503 Mon Sep 17 00:00:00 2001 From: g-kiss <70820303+g-kiss@users.noreply.github.com> Date: Mon, 7 Sep 2020 20:42:56 +0200 Subject: [PATCH 3/7] Click handling --- pyShelly/switch.py | 47 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/pyShelly/switch.py b/pyShelly/switch.py index 7168fba..e92b89c 100644 --- a/pyShelly/switch.py +++ b/pyShelly/switch.py @@ -46,7 +46,6 @@ def __init__(self, block, channel, self.kg_last_event_cnt = None self.kg_last_state = None self.kg_click_count = 0 - self.kg_click_error = False self.kg_click_timer = None self.kg_send_event_events = None self.kg_send_event_click_count = None @@ -54,25 +53,17 @@ def __init__(self, block, channel, self.kg_momentary_button = False def kg_send_event(self): - if self.kg_click_error: - self.kg_click_error = False - self.kg_last_event = "" - self.kg_click_count = 0 - else: -# LOGGER.warning(self.kg_last_event) -# LOGGER.warning(self.kg_click_count) - - if self.kg_momentary_button: - self.kg_send_event_events = self.kg_last_event - self.kg_send_event_click_count = 0 - else: - self.kg_send_event_events = "" - self.kg_send_event_click_count = self.kg_click_count + if self.kg_momentary_button: + self.kg_send_event_events = self.kg_last_event + self.kg_send_event_click_count = 0 + else: + self.kg_send_event_events = "" + self.kg_send_event_click_count = self.kg_click_count - self.kg_last_event = "" - self.kg_click_count = 0 + self.kg_last_event = "" + self.kg_click_count = 0 - self.raise_updated(True) + self.raise_updated(True) def update_coap(self, payload): @@ -116,9 +107,6 @@ def update_coap(self, payload): if not kg_curr_event_cnt is None: if not self.kg_last_event_cnt is None and not self.kg_last_state is None: if kg_curr_event_cnt != self.kg_last_event_cnt: -# if kg_curr_event_cnt - self.kg_last_event_cnt != 1: -# self.kg_click_error = True - if kg_curr_event == "S": if self.kg_last_state == 1: self.kg_click_count += 1 @@ -135,21 +123,16 @@ def update_coap(self, payload): if self.kg_momentary_button: if kg_curr_state != self.kg_last_state: self.kg_click_count += 1 + self.kg_send_event_events = self.kg_last_event + "LSTART" + self.kg_send_event_click_count = 0 + self.raise_updated(True) else: if kg_curr_state != self.kg_last_state: self.kg_click_count += 1 -# if kg_curr_state == self.kg_last_state: -# self.kg_click_count += 2 - if kg_curr_event_cnt - self.kg_last_event_cnt > 1: self.kg_click_count += kg_curr_event_cnt - self.kg_last_event_cnt - 1 -# if self.kg_click_count == 0: -# self.kg_click_count += 2 -# if kg_curr_state == 1 and self.kg_last_state == 1: -# self.kg_click_count += 2 - self.kg_last_event += kg_curr_event if not self.kg_momentary_button or kg_curr_state == 0: @@ -165,12 +148,6 @@ def update_coap(self, payload): self.kg_last_state = kg_curr_state self.kg_last_event_cnt = kg_curr_event_cnt - - - - - - state = self.coap_get(payload, self._position) event_cnt = self.coap_get(payload, self._event_cnt_pos) From 3d784ee03fec690c38a23e36cd80a20af67af24f Mon Sep 17 00:00:00 2001 From: g-kiss <70820303+g-kiss@users.noreply.github.com> Date: Wed, 9 Sep 2020 13:44:43 +0200 Subject: [PATCH 4/7] Update switch.py --- pyShelly/switch.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pyShelly/switch.py b/pyShelly/switch.py index e92b89c..0198d46 100644 --- a/pyShelly/switch.py +++ b/pyShelly/switch.py @@ -47,8 +47,8 @@ def __init__(self, block, channel, self.kg_last_state = None self.kg_click_count = 0 self.kg_click_timer = None - self.kg_send_event_events = None - self.kg_send_event_click_count = None + self.kg_send_event_events = "" + self.kg_send_event_click_count = 0 self.kg_start_state = None self.kg_momentary_button = False @@ -120,18 +120,18 @@ def update_coap(self, payload): kg_curr_event = "S"*(kg_curr_event_cnt - self.kg_last_event_cnt) if kg_curr_event == "L": - if self.kg_momentary_button: - if kg_curr_state != self.kg_last_state: - self.kg_click_count += 1 - self.kg_send_event_events = self.kg_last_event + "LSTART" - self.kg_send_event_click_count = 0 - self.raise_updated(True) - else: - if kg_curr_state != self.kg_last_state: - self.kg_click_count += 1 - - if kg_curr_event_cnt - self.kg_last_event_cnt > 1: - self.kg_click_count += kg_curr_event_cnt - self.kg_last_event_cnt - 1 + if self.kg_momentary_button: + if kg_curr_state != self.kg_last_state: + self.kg_click_count += 1 + self.kg_send_event_events = self.kg_last_event + "LSTART" + self.kg_send_event_click_count = 0 + self.raise_updated(True) + else: + if kg_curr_state != self.kg_last_state: + self.kg_click_count += 1 + + if kg_curr_event_cnt - self.kg_last_event_cnt > 1: + self.kg_click_count += kg_curr_event_cnt - self.kg_last_event_cnt - 1 self.kg_last_event += kg_curr_event From b0840b31b72b370a3008ac4b7e48d8e0e06e3a74 Mon Sep 17 00:00:00 2001 From: g-kiss <70820303+g-kiss@users.noreply.github.com> Date: Sat, 12 Sep 2020 17:20:13 +0200 Subject: [PATCH 5/7] Update switch.py --- pyShelly/switch.py | 62 +++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/pyShelly/switch.py b/pyShelly/switch.py index 0198d46..a62ba9c 100644 --- a/pyShelly/switch.py +++ b/pyShelly/switch.py @@ -70,36 +70,33 @@ def update_coap(self, payload): """Get the power""" # Start state Action CoAP # ----------------------------------------------------------------------------------------------------------- -# 0 [0,2101,0],[0,2102,"L"],[0,2103,42] -# 1 Fast click [0,2101,0],[0,2102,"S"],[0,2103,43] * +# 0 [0,2101,0],[0,2102," "],[0,2103,42] +# 1 Fast click [0,2101,0],[0,2102,"S"],[0,2103,43] # -# 0 [0,2101,0],[0,2102,"S"],[0,2103,43] -# 1 Normal click [0,2101,1],[0,2102,"S"],[0,2103,43] -# [0,2101,0],[0,2102,"S"],[0,2103,44] * +# 0 [0,2101,0],[0,2102," "],[0,2103,43] +# 1 Normal click [0,2101,1],[0,2102," "],[0,2103,43] +# [0,2101,0],[0,2102,"S"],[0,2103,44] # -# 0 [0,2101,0],[0,2102,"S"],[0,2103,45] -# 2 Fast click [0,2101,0],[0,2102,"S"],[0,2103,47] ** +# 0 [0,2101,0],[0,2102," "],[0,2103,45] +# 2 Fast click [0,2101,0],[0,2102,"S"],[0,2103,47] # -# 0 [0,2101,0],[0,2102,"L"],[0,2103,461] -# 1 Long click [0,2101,1],[0,2102,"L"],[0,2103,461] -# [0,2101,1],[0,2102,"L"],[0,2103,462] * -# [0,2101,0],[0,2102,"L"],[0,2103,462] +# 0 [0,2101,0],[0,2102," "],[0,2103,461] +# 1 Long click [0,2101,1],[0,2102," "],[0,2103,461] +# slow [0,2101,1],[0,2102,"L"],[0,2103,462] +# [0,2101,0],[0,2102," "],[0,2103,462] # -# 0 [0,2101,0],[0,2102,"S"],[0,2103,67] -# 1 Long click [0,2101,1],[0,2102,"S"],[0,2103,67] -# [0,2101,0],[0,2102,"L"],[0,2103,68] * +# 0 [0,2101,0],[0,2102," "],[0,2103,67] +# 1 Long click [0,2101,1],[0,2102," "],[0,2103,67] +# fast [0,2101,0],[0,2102,"L"],[0,2103,68] # -# 1 [0,2101,1],[0,2102,"L"],[0,2103,74] // Ez 0 clicket ad -# 1 Fast click [0,2101,1],[0,2102,"L"],[0,2103,74] -# [0,2101,1],[0,2102,"L"],[0,2103,75] * +# 1 [0,2101,1],[0,2102," "],[0,2103,74] +# 1 Fast click [0,2101,1],[0,2102," "],[0,2103,74] +# [0,2101,1],[0,2102,"L"],[0,2103,75] # -# 1 [0,2101,1],[0,2102,"L"],[0,2103,466] -# 1 Normal click [0,2101,0],[0,2102,"L"],[0,2103,466] -# [0,2101,1],[0,2102,"L"],[0,2103,466] -# [0,2101,1],[0,2102,"L"],[0,2103,467] * - - if not self.kg_click_timer is None: - self.kg_click_timer.cancel() +# 1 [0,2101,1],[0,2102," "],[0,2103,466] +# 1 Normal click [0,2101,0],[0,2102," "],[0,2103,466] +# [0,2101,1],[0,2102," "],[0,2103,466] +# [0,2101,1],[0,2102,"L"],[0,2103,467] kg_curr_state = self.coap_get(payload, self._position) kg_curr_event = self.coap_get(payload, self._event_pos) @@ -107,6 +104,10 @@ def update_coap(self, payload): if not kg_curr_event_cnt is None: if not self.kg_last_event_cnt is None and not self.kg_last_state is None: if kg_curr_event_cnt != self.kg_last_event_cnt: + if not self.kg_click_timer is None: + self.kg_click_timer.cancel() + self.kg_click_timer = None + if kg_curr_event == "S": if self.kg_last_state == 1: self.kg_click_count += 1 @@ -127,11 +128,16 @@ def update_coap(self, payload): self.kg_send_event_click_count = 0 self.raise_updated(True) else: - if kg_curr_state != self.kg_last_state: + if self.kg_last_state == 0: + self.kg_click_count += 1 + else: + self.kg_click_count += 2 + + if kg_curr_state == 0: self.kg_click_count += 1 if kg_curr_event_cnt - self.kg_last_event_cnt > 1: - self.kg_click_count += kg_curr_event_cnt - self.kg_last_event_cnt - 1 + self.kg_click_count += (kg_curr_event_cnt - self.kg_last_event_cnt - 1) * 2 self.kg_last_event += kg_curr_event @@ -140,6 +146,10 @@ def update_coap(self, payload): self.kg_click_timer.start() if kg_curr_event_cnt == self.kg_last_event_cnt and kg_curr_state != self.kg_last_state: + if not self.kg_click_timer is None: + self.kg_click_timer.cancel() + self.kg_click_timer = None + self.kg_click_count += 1 if not self.kg_momentary_button or kg_curr_state == 0: From 32c9e8eee8e7a3e41536136aae0682b83f7d0cfd Mon Sep 17 00:00:00 2001 From: g-kiss <70820303+g-kiss@users.noreply.github.com> Date: Sat, 12 Sep 2020 17:23:22 +0200 Subject: [PATCH 6/7] Update switch.py --- pyShelly/switch.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pyShelly/switch.py b/pyShelly/switch.py index a62ba9c..6b30682 100644 --- a/pyShelly/switch.py +++ b/pyShelly/switch.py @@ -182,7 +182,6 @@ def update_coap(self, payload): self._update(SRC_COAP, state, {'last_event' : self.last_event, 'event_cnt' : self.event_cnt}) - def update_status_information(self, status): """Update the status information.""" new_state = None From 86f4a0ed5840ec01c32539f9bb6222001cbbd1d0 Mon Sep 17 00:00:00 2001 From: g-kiss <70820303+g-kiss@users.noreply.github.com> Date: Mon, 14 Dec 2020 11:31:52 +0100 Subject: [PATCH 7/7] dimmer --- pyShelly/dimmer.py | 15 +++++++++++++++ pyShelly/switch.py | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/pyShelly/dimmer.py b/pyShelly/dimmer.py index 0214b0b..4c8a5b9 100644 --- a/pyShelly/dimmer.py +++ b/pyShelly/dimmer.py @@ -90,6 +90,21 @@ def turn_on(self, brightness=None): def turn_off(self): self._send_data(False) + def dimming(self, dim_type, state): + url = self.url + "?" + if not state: + url = url + "turn=on&" + if dim_type == "dim_up": + url = url + "dim=up" + elif dim_type == "dim_down": + url = url + "dim=down" + elif dim_type == "dim_stop": + url = url + "dim=stop" + else: + return + + self._send_command(url) + def get_dim_value(self): return self.brightness diff --git a/pyShelly/switch.py b/pyShelly/switch.py index 6b30682..ce2501a 100644 --- a/pyShelly/switch.py +++ b/pyShelly/switch.py @@ -152,6 +152,12 @@ def update_coap(self, payload): self.kg_click_count += 1 + if self.kg_momentary_button and kg_curr_state == 0 and len(self.kg_last_event) > 0: + if self.kg_last_event[-1] == "L": + self.kg_send_event_events = self.kg_last_event + "STOP" + self.kg_send_event_click_count = 0 + self.raise_updated(True) + if not self.kg_momentary_button or kg_curr_state == 0: self.kg_click_timer = Timer(0.7, self.kg_send_event) self.kg_click_timer.start()