-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathha.py
54 lines (44 loc) · 1.53 KB
/
ha.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
import json
import yaml
# these custom tags secretly register with the loader (yaml.SafeLoader) through the YAMLObjectMetaclass
# see list of HA specific tags see https://github.com/home-assistant/core/blob/56b99d2bc63755ddbe2273c4768c7345c2ee8abc/homeassistant/util/yaml/loader.py#L401
for tag in [
'!include',
'!env_var',
'!secret',
'!include_dir_list',
'!include_dir_merge_list',
'!include_dir_merge_named',
'!include_dir_merge_named',
'!input',
]:
class _(yaml.YAMLObject):
yaml_loader = yaml.SafeLoader
yaml_tag = tag
def __init__(self, val):
self.val = val
@classmethod
def from_yaml(cls, loader, node):
return cls(node.value)
def read_hass_configuration_yaml():
files = ['/homeassistant/configuration.yaml', '/config/configuration.yaml', 'configuration.yaml']
for fn in files:
try:
with open(fn, "r") as fp:
return yaml.safe_load(fp)
# return yaml.load(fp, Loader=yaml.Loader)
except FileNotFoundError as e:
pass
raise FileNotFoundError('none of these files found %s' % files)
def read_user_options():
files = ['/data/options.json', 'options.json']
for fn in files:
try:
with open(fn, 'r') as f:
return json.load(f)
except FileNotFoundError:
pass
raise FileNotFoundError('none of these files found %s' % files)
if __name__ == "__main__":
conf = read_hass_configuration_yaml()
print(conf)