-
Notifications
You must be signed in to change notification settings - Fork 0
/
minisplit.py
42 lines (33 loc) · 905 Bytes
/
minisplit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
""" Control a minisplit via IR. """
import broadlink
import device
import datetime
import gin
import os
from pathlib import Path
from typing import List
@gin.configurable
class Minisplit(device.Device):
def __init__(self, on_cmd:bytes, off_cmd:bytes, schedule:List[int]):
super(Minisplit, self).__init__('minisplit')
self._on_cmd = on_cmd
self._off_cmd = off_cmd
self._device = broadlink.discover()[0]
self._device.auth()
self._schedule = schedule
def turn_on(self):
try:
self._device.send_data(self._on_cmd)
return True
except:
return False
def turn_off(self):
try:
self._device.send_data(self._off_cmd)
return True
except:
return False
def should_be_on(self):
return datetime.datetime.now().hour in self._schedule
gin.parse_config_file(os.path.join(
str(Path.home()), '.autohome/broadlink_cfg.gin'))