-
Notifications
You must be signed in to change notification settings - Fork 0
/
nature_remo.py
52 lines (40 loc) · 1.35 KB
/
nature_remo.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
43
44
45
46
47
48
49
50
51
52
from remo import NatureRemoAPI
class NatureRemo:
appliances = None
def __init__(self, acccess_token: str):
self.nr_api = NatureRemoAPI(acccess_token)
self.appliances = self.nr_api.get_appliances()
self.devices = self.nr_api.get_devices()
def update_appliances(self):
"""Update the appliances list.
"""
self.appliances = self.nr_api.get_appliances()
def search_appliance_by_nickname(
self,
nickname: str,
):
"""Search the appliance by the nickname.
Args:
nickname (str): Nickname of the appliance.
Returns:
app (Appliance): Searched appliance object.
"""
for app in self.appliances:
if app.nickname == nickname:
return app
def get_current_state(
self,
target_nickname: str,
):
"""Get the current state of the appliance.
Args:
target_nickname (str): Nickname of the device.
Returns:
current_state (str): Current state of the device.
"""
self.update_appliances()
target_device = self.search_appliance_by_nickname(
target_nickname)
# FIXME Change the state int the code to match your environment.
current_state = target_device.light.state.power
return current_state