Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sp3s plug #94

Open
fapgomes opened this issue May 10, 2021 · 4 comments
Open

Add support for sp3s plug #94

fapgomes opened this issue May 10, 2021 · 4 comments

Comments

@fapgomes
Copy link

fapgomes commented May 10, 2021

Hi,

Can you import this changes to support sp3s plug?

--- old/mqtt.py 2021-05-10 18:01:40.735388521 +0100
+++ mqtt.py     2021-05-10 17:36:28.787577208 +0100
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import paho.mqtt.client as paho  # pip install paho-mqtt
 import broadlink  # pip install broadlink
@@ -108,7 +108,7 @@
 
         # SP1/2 / MP1/ BG1 power control
         if command == 'power':
-            if device.type == 'SP1' or device.type == 'SP2':
+            if device.type == 'SP1' or device.type == 'SP2' or device.type == 'SP3S':
                 state = action == 'on' or action == '1'
                 logging.debug("Setting power state to {0}".format(state))
                 device.set_power(1 if state else 0)
@@ -384,6 +384,8 @@
             device = broadlink.sp1(host=host, mac=mac, devtype=0)
         elif device_type == 'sp2':
             device = broadlink.sp2(host=host, mac=mac, devtype=0x2711)
+        elif device_type == 'sp3s':
+            device = broadlink.sp3s(host=host, mac=mac, devtype=0x947a)
         elif device_type == 'a1':
             device = broadlink.a1(host=host, mac=mac, devtype=0x2714)
         elif device_type == 'mp1':
@@ -414,7 +416,17 @@
         tt.start()
 
     broadlink_sp_energy_interval = cf.get('broadlink_sp_energy_interval', 0)
-    if device.type == 'SP2' and broadlink_sp_energy_interval > 0:
+    broadlink_sp2_energy = cf.get('broadlink_sp2_energy', False)
+    if device.type == 'SP2' and broadlink_sp_energy_interval > 0 and broadlink_sp2_energy == True:
+        scheduler = sched.scheduler(time.time, time.sleep)
+        scheduler.enter(broadlink_sp_energy_interval, 1, broadlink_sp_energy_timer,
+                        [scheduler, broadlink_sp_energy_interval, device, mqtt_prefix])
+        # scheduler.run()
+        tt = SchedulerThread(scheduler)
+        tt.daemon = True
+        tt.start()
+
+    if device.type == 'SP3S' and broadlink_sp_energy_interval > 0:
         scheduler = sched.scheduler(time.time, time.sleep)
         scheduler.enter(broadlink_sp_energy_interval, 1, broadlink_sp_energy_timer,
                         [scheduler, broadlink_sp_energy_interval, device, mqtt_prefix])

Best Regards,
Fernando Gomes

@eschava
Copy link
Owner

eschava commented May 28, 2021

Thanks for this patch! Committed it but w/o part related to broadlink_sp2_energy parameter
Why would you need it?

@fapgomes
Copy link
Author

Because I've one SP2 socket, that doesn't support energy monitoring, and give error without this code.

@eschava
Copy link
Owner

eschava commented May 28, 2021

Do you use 'multiple_lookup'?

@fapgomes
Copy link
Author

Yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants