summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-01-04 03:44:07 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-01-04 03:44:07 +0300
commitd549f428cbbd54c49a90f92928e670d373c4a0d9 (patch)
treeb895a216a37483c082af6f20b2d6aef8560db7b3
parent00de2339b4a61921c4b8789883e5c77b4528a60b (diff)
config: use get_addr() instead of parse_addr(config[...])
-rwxr-xr-xsrc/camera_node.py8
-rwxr-xr-xsrc/gpiorelayd.py5
-rw-r--r--src/home/config/config.py4
-rwxr-xr-xsrc/ipcam_server.py3
-rwxr-xr-xsrc/relay_mqtt_http_proxy.py4
-rwxr-xr-xsrc/sound_node.py3
-rwxr-xr-xsrc/sound_sensor_server.py2
-rwxr-xr-xsrc/temphumd.py3
-rwxr-xr-xsrc/web_api.py3
9 files changed, 16 insertions, 19 deletions
diff --git a/src/camera_node.py b/src/camera_node.py
index 2df8df7..9ff0e77 100755
--- a/src/camera_node.py
+++ b/src/camera_node.py
@@ -5,7 +5,7 @@ import time
from home.config import config
from home.media import MediaNodeServer, ESP32CameraRecordStorage, CameraRecorder
from home.camera import CameraType, esp32
-from home.util import parse_addr, Addr
+from home.util import Addr
from home import http
@@ -69,7 +69,7 @@ if __name__ == '__main__':
recorder_kwargs = {}
camera_type = CameraType(config['camera']['type'])
if camera_type == CameraType.ESP32:
- recorder_kwargs['stream_addr'] = parse_addr(config['camera']['web_addr']) # this is not a mistake, we don't use stream_addr for esp32-cam anymore
+ recorder_kwargs['stream_addr'] = config.get_addr('camera.web_addr') # this is not a mistake, we don't use stream_addr for esp32-cam anymore
storage = ESP32CameraRecordStorage(config['node']['storage'])
else:
raise RuntimeError(f'unsupported camera type {camera_type}')
@@ -82,6 +82,6 @@ if __name__ == '__main__':
server = ESP32CameraNodeServer(
recorder=recorder,
storage=storage,
- web_addr=parse_addr(config['camera']['web_addr']),
- addr=parse_addr(config['node']['listen']))
+ web_addr=config.get_addr('camera.web_addr'),
+ addr=config.get_addr('node.listen'))
server.run()
diff --git a/src/gpiorelayd.py b/src/gpiorelayd.py
index cd2941f..85015a7 100755
--- a/src/gpiorelayd.py
+++ b/src/gpiorelayd.py
@@ -4,7 +4,6 @@ import os
import sys
from home.config import config
-from home.util import parse_addr
from home.relay.sunxi_h3_server import RelayServer
logger = logging.getLogger(__name__)
@@ -17,8 +16,8 @@ if __name__ == '__main__':
config.load()
try:
- s = RelayServer(pinname=config['relayd']['pin'],
- addr=parse_addr(config['relayd']['listen']))
+ s = RelayServer(pinname=config.get('relayd.pin'),
+ addr=config.get_addr('relayd.listen'))
s.run()
except KeyboardInterrupt:
logger.info('Exiting...')
diff --git a/src/home/config/config.py b/src/home/config/config.py
index 0c0e944..4681685 100644
--- a/src/home/config/config.py
+++ b/src/home/config/config.py
@@ -6,6 +6,7 @@ import os
from os.path import join, isdir, isfile
from typing import Optional, Any, MutableMapping
from argparse import ArgumentParser
+from ..util import parse_addr
def _get_config_path(name: str) -> str:
@@ -118,6 +119,9 @@ class ConfigStore:
cur = self.data[k]
raise KeyError(f'option {key} not found')
+ def get_addr(self, key: str):
+ return parse_addr(self.get(key))
+
def items(self):
return self.data.items()
diff --git a/src/ipcam_server.py b/src/ipcam_server.py
index 07b216b..3fdf888 100755
--- a/src/ipcam_server.py
+++ b/src/ipcam_server.py
@@ -10,7 +10,6 @@ import home.telegram.aio as telegram
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from home.config import config
-from home.util import parse_addr
from home import http
from home.database.sqlite import SQLiteBase
from home.camera import util as camutil
@@ -507,5 +506,5 @@ if __name__ == '__main__':
except KeyError:
pass
- server = IPCamWebServer(parse_addr(config['server']['listen']))
+ server = IPCamWebServer(config.get_addr('server.listen'))
server.run()
diff --git a/src/relay_mqtt_http_proxy.py b/src/relay_mqtt_http_proxy.py
index ab8a138..51a4e21 100755
--- a/src/relay_mqtt_http_proxy.py
+++ b/src/relay_mqtt_http_proxy.py
@@ -5,7 +5,6 @@ from home.mqtt import MQTTRelay, MQTTRelayDevice, MQTTRelayState
from home.mqtt.payload import MQTTPayload
from home.mqtt.payload.relay import InitialStatPayload, StatPayload
from typing import Optional
-from home.util import parse_addr
mqtt_relay: Optional[MQTTRelay] = None
relay_states: dict[str, MQTTRelayState] = {}
@@ -60,9 +59,8 @@ if __name__ == '__main__':
mqtt_relay.set_message_callback(on_mqtt_message)
mqtt_relay.connect_and_loop(loop_forever=False)
- proxy = RelayMqttHttpProxy(parse_addr(config.get('server.listen')))
+ proxy = RelayMqttHttpProxy(config.get_addr('server.listen'))
try:
proxy.run()
except KeyboardInterrupt:
mqtt_relay.disconnect()
-
diff --git a/src/sound_node.py b/src/sound_node.py
index 7d8ba1a..9d53362 100755
--- a/src/sound_node.py
+++ b/src/sound_node.py
@@ -3,7 +3,6 @@ import os
from typing import Optional
-from home.util import parse_addr
from home.config import config
from home.audio import amixer
from home.media import MediaNodeServer, SoundRecordStorage, SoundRecorder
@@ -87,5 +86,5 @@ if __name__ == '__main__':
server = SoundNodeServer(recorder=recorder,
storage=storage,
- addr=parse_addr(config['node']['listen']))
+ addr=config.get_addr('node.listen'))
server.run()
diff --git a/src/sound_sensor_server.py b/src/sound_sensor_server.py
index c63d14a..aa62608 100755
--- a/src/sound_sensor_server.py
+++ b/src/sound_sensor_server.py
@@ -190,7 +190,7 @@ if __name__ == '__main__':
finished_handler=partial(record_finished, MediaNodeType.CAMERA))
try:
- server = SoundSensorServer(parse_addr(config['server']['listen']), HitHandler)
+ server = SoundSensorServer(config.get_addr('server.listen'), HitHandler)
server.run()
except KeyboardInterrupt:
interrupted = True
diff --git a/src/temphumd.py b/src/temphumd.py
index 563d192..f4d1fca 100755
--- a/src/temphumd.py
+++ b/src/temphumd.py
@@ -6,7 +6,6 @@ import logging
from typing import Optional
from home.config import config
-from home.util import parse_addr
from home.temphum import SensorType, create_sensor, TempHumSensor
logger = logging.getLogger(__name__)
@@ -72,7 +71,7 @@ if __name__ == '__main__':
int(config['sensor']['bus']))
try:
- host, port = parse_addr(config['server']['listen'])
+ host, port = config.get_addr('server.listen')
asyncio.run(run_server(host, port))
except KeyboardInterrupt:
logging.info('Exiting...')
diff --git a/src/web_api.py b/src/web_api.py
index 672bfb8..c00c372 100755
--- a/src/web_api.py
+++ b/src/web_api.py
@@ -7,7 +7,6 @@ from datetime import datetime, timedelta
from aiohttp import web
from home import http
-from home.util import parse_addr
from home.config import config, is_development_mode
from home.database import BotsDatabase, SensorsDatabase, InverterDatabase
from home.database.inverter_time_formats import *
@@ -234,5 +233,5 @@ if __name__ == '__main__':
loop = asyncio.get_event_loop()
- server = WebAPIServer(parse_addr(config['server']['listen']))
+ server = WebAPIServer(config.get_addr('server.listen'))
server.run()