mirror of
https://github.com/fmtr/haco.git
synced 2026-12-05 06:10:08 -05:00
Read in options.json
This commit is contained in:
parent
c17db53053
commit
45d05df6f9
3 changed files with 21 additions and 11 deletions
|
|
@ -4,6 +4,8 @@ var mod = module("haco")
|
||||||
|
|
||||||
var logger=tools.logger.logger
|
var logger=tools.logger.logger
|
||||||
|
|
||||||
|
logger.level=4
|
||||||
|
logger.log_repl=true
|
||||||
|
|
||||||
var CALLBACK_MAP={}
|
var CALLBACK_MAP={}
|
||||||
var BRANCH='release'
|
var BRANCH='release'
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@
|
||||||
|
|
||||||
export HACO_IS_ADDON=true
|
export HACO_IS_ADDON=true
|
||||||
export HACO_CONFIGS_PATH="/config/haco"
|
export HACO_CONFIGS_PATH="/config/haco"
|
||||||
|
export HACO_OPTIONS_PATH="/data/options.json"
|
||||||
export MQTT_HOST="$(bashio::services mqtt 'host')"
|
export MQTT_HOST="$(bashio::services mqtt 'host')"
|
||||||
export MQTT_PASSWORD="$(bashio::services mqtt 'password')"
|
export MQTT_PASSWORD="$(bashio::services mqtt 'password')"
|
||||||
export MQTT_PORT="$(bashio::services mqtt 'port')"
|
export MQTT_PORT="$(bashio::services mqtt 'port')"
|
||||||
export MQTT_USERNAME="$(bashio::services mqtt 'username')"
|
export MQTT_USERNAME="$(bashio::services mqtt 'username')"
|
||||||
|
|
||||||
cp /data/options.json /config/haco/options.json
|
|
||||||
|
|
||||||
haco-daemon
|
haco-daemon
|
||||||
|
|
@ -1,27 +1,36 @@
|
||||||
from importlib import reload
|
from importlib import reload
|
||||||
|
|
||||||
import importlib.util
|
import importlib.util
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import yaml
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from haco import tools
|
||||||
from haco.control import Control
|
from haco.control import Control
|
||||||
from haco.device import Device
|
from haco.device import Device
|
||||||
|
|
||||||
CONFIGS_PATH = Path(os.environ['HACO_CONFIGS_PATH'])
|
CONFIGS_PATH = Path(os.environ['HACO_CONFIGS_PATH'])
|
||||||
|
OPTIONS_PATH = Path(os.environ['HACO_OPTIONS_PATH'])
|
||||||
|
|
||||||
|
|
||||||
def load_yaml_file(file_path):
|
def load_json(file_path):
|
||||||
with open(file_path, 'r') as yaml_file:
|
with open(file_path, 'r') as json_file:
|
||||||
data = yaml.safe_load(yaml_file)
|
data = json.loads(json_file.read())
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def load_controls_from_directory(directory_path):
|
def load_controls_from_directory():
|
||||||
assn = load_yaml_file(directory_path / 'assignments.yaml')
|
if not CONFIGS_PATH.exists():
|
||||||
|
tools.logger.warning(f'Configs path does not exist. Will be created: {CONFIGS_PATH}')
|
||||||
|
CONFIGS_PATH.mkdir()
|
||||||
|
|
||||||
|
options = load_json(OPTIONS_PATH)
|
||||||
|
|
||||||
controls = []
|
controls = []
|
||||||
for name, macs in assn.items():
|
for data in options['assignments']:
|
||||||
|
|
||||||
|
name = data['config']
|
||||||
|
macs = data['identifier']
|
||||||
|
|
||||||
if type(macs) is not list:
|
if type(macs) is not list:
|
||||||
macs = [macs]
|
macs = [macs]
|
||||||
|
|
@ -32,7 +41,7 @@ def load_controls_from_directory(directory_path):
|
||||||
|
|
||||||
args = {'mac': mac}
|
args = {'mac': mac}
|
||||||
|
|
||||||
py_file = directory_path / Path(name).with_suffix('.py')
|
py_file = CONFIGS_PATH / Path(name).with_suffix('.py')
|
||||||
module_name = py_file.stem
|
module_name = py_file.stem
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -57,6 +66,6 @@ def load_controls_from_directory(directory_path):
|
||||||
|
|
||||||
|
|
||||||
def load_devices():
|
def load_devices():
|
||||||
devices_args = load_controls_from_directory(CONFIGS_PATH)
|
devices_args = load_controls_from_directory()
|
||||||
devices = [Device(**args) for args in devices_args]
|
devices = [Device(**args) for args in devices_args]
|
||||||
return devices
|
return devices
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue