-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
74 lines (60 loc) · 2.67 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Entry point for StreamController to load the plugin.
"""
import sys
from pathlib import Path
from typing import Dict, Any
ABSOLUTE_PLUGIN_PATH = str(Path(__file__).parent.parent.absolute())
sys.path.insert(0, ABSOLUTE_PLUGIN_PATH)
from src.backend.PluginManager.ActionHolder import ActionHolder
from src.backend.PluginManager.PluginBase import PluginBase
from de_gensyn_HomeAssistantPlugin import const
from de_gensyn_HomeAssistantPlugin.actions.HomeAssistantAction.home_asistant_action import \
HomeAssistantAction
from de_gensyn_HomeAssistantPlugin.backend.home_assistant import HomeAssistantBackend
class HomeAssistant(PluginBase): # pylint: disable=too-few-public-methods
"""
The plugin class to be loaded by Stream Controller.
"""
def __init__(self):
super().__init__()
self.home_assistant_action_holder = ActionHolder(
plugin_base=self,
action_base=HomeAssistantAction,
action_id="de_gensyn_HomeAssistantPlugin::HomeAssistantAction",
action_name=const.HOME_ASSISTANT,
)
self.add_action_holder(self.home_assistant_action_holder)
self.register(
plugin_name=const.HOME_ASSISTANT,
github_repo="https://github.com/gensyn/de_gensyn_HomeAssistantPlugin",
plugin_version="0.9.6-beta",
app_version="1.5.0-beta"
)
settings = self.get_settings()
host = settings.get(const.SETTING_HOST, const.EMPTY_STRING)
port = settings.get(const.SETTING_PORT, const.EMPTY_STRING)
ssl = settings.get(const.SETTING_SSL, True)
verify_certificate = settings.get(const.SETTING_VERIFY_CERTIFICATE, True)
token = settings.get(const.SETTING_TOKEN, const.EMPTY_STRING)
self.backend = HomeAssistantBackend()
self.backend.set_host(host)
self.backend.set_port(port)
self.backend.set_ssl(ssl)
self.backend.set_verify_certificate(verify_certificate)
self.backend.set_token(token)
def set_settings(self, settings: Dict[str, Any]):
"""
Saves the settings to the disk.
"""
super().set_settings(settings)
host = settings.get(const.SETTING_HOST, const.EMPTY_STRING)
port = settings.get(const.SETTING_PORT, const.EMPTY_STRING)
ssl = settings.get(const.SETTING_SSL, True)
verify_certificate = settings.get(const.SETTING_VERIFY_CERTIFICATE, True)
token = settings.get(const.SETTING_TOKEN, const.EMPTY_STRING)
self.backend.set_host(host)
self.backend.set_port(port)
self.backend.set_ssl(ssl)
self.backend.set_verify_certificate(verify_certificate)
self.backend.set_token(token)