-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsonoff_control.py
More file actions
21 lines (18 loc) · 781 Bytes
/
Copy pathsonoff_control.py
File metadata and controls
21 lines (18 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import json, requests, warnings
from urllib3.connectionpool import InsecureRequestWarning
class SonoffController():
def __init__(self, ip_server, port_server):
self.switch0 = False
self.switch1 = False
self.server_ip = ip_server
self.server_port = str(port_server)
def set_state(self, switch0_state=False, switch1_state=False):
with warnings.catch_warnings():
warnings.simplefilter('ignore', InsecureRequestWarning)
req_state = requests.post("https://" + self.server_ip + ":" + self.server_port + "/state", json=
{
"0": switch0_state,
"1": switch1_state
}, headers={
"Content-Type": "application/json"
}, verify=False)