Fix
This commit is contained in:
parent
9bf21d04e3
commit
5a14d251b4
@ -7,14 +7,6 @@ from asyncio import Queue, Task, Event, Lock
|
||||
from typing import Callable, Dict, Optional
|
||||
import websockets
|
||||
|
||||
"""
|
||||
- sender fun, bekommt packete per queue
|
||||
- receiver fun, schreibt packete in map id -> msg bzw events in queue(?)
|
||||
- blockieren beim auf antwort warten per "pseudo-queue", in die sich alle wartenden eintragen und warten, dass sie leer ist, receiver leert queue wenn irgendeine nachricht rein kommt
|
||||
- andere (auch außerhalb) können dann auf neue daten warten und ggf verarbeiten
|
||||
|
||||
"""
|
||||
|
||||
|
||||
class HomeAssistantAPI:
|
||||
def __init__(self, token: str, url: str) -> None:
|
||||
@ -143,4 +135,3 @@ class HomeAssistantAPI:
|
||||
return device_state
|
||||
|
||||
return None
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
#!/usr/bin/env bashio
|
||||
|
||||
python3 /srv/sync_ha_fb.py
|
||||
python3 /srv/sync_ha_fb.py /data/options.json
|
@ -1,11 +1,8 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
hier die verbindungen zu HA aufbauen etc
|
||||
außerdem das vergleichen der werte und dass anstoßen der updates
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from typing import Dict
|
||||
import sys
|
||||
|
||||
from fritzbox import FritzBox
|
||||
from homeassistant import HomeAssistantAPI
|
||||
@ -15,6 +12,7 @@ import json
|
||||
sensor_mappings = {}
|
||||
thermostate_mappings = {}
|
||||
|
||||
|
||||
async def handle_event(idx: int):
|
||||
logging.debug(f"Wait for events for {idx}")
|
||||
|
||||
@ -85,42 +83,16 @@ async def init(ha: HomeAssistantAPI):
|
||||
asyncio.get_running_loop().stop()
|
||||
|
||||
|
||||
async def migrate_config(config_path: str, ha: HomeAssistantAPI):
|
||||
config = json.load(open(config_path))
|
||||
therm_ids = {}
|
||||
for state in await ha.get_states():
|
||||
if state["entity_id"].startswith("climate.") and "friendly_name" in state["attributes"].keys():
|
||||
therm_ids[state["attributes"]["friendly_name"]] = state["entity_id"]
|
||||
|
||||
mappings = []
|
||||
for mapping in config["mappings"]:
|
||||
if not mapping["thermostate"].startswith("climate."):
|
||||
mapping["thermostate"] = therm_ids[mapping["thermostate"]]
|
||||
mappings.append(mapping)
|
||||
config["mappings"] = mappings
|
||||
json.dump(open(config_path), config)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.INFO, format="[%(asctime)s] [%(levelname)s] %(message)s")
|
||||
config_path = "/data/options.json"
|
||||
config_path = "options.json"
|
||||
config_path = sys.argv[1]
|
||||
config = json.load(open(config_path))
|
||||
logging.debug(config)
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
fb = FritzBox(config["fritzbox"]["url"], config["fritzbox"]["password"])
|
||||
supervisor_url = "ws://supervisor/core/websocket"
|
||||
supervisor_url = "ws://192.168.124.187:8123/api/websocket"
|
||||
ha = HomeAssistantAPI(os.environ["SUPERVISOR_TOKEN"], supervisor_url)
|
||||
|
||||
if '"thermostate": "climate.' not in open(config_path).read():
|
||||
config = loop.run_until_complete(migrate_config(config_path, ha))
|
||||
logging.info(config)
|
||||
exit()
|
||||
|
||||
for mapping in config["mappings"]:
|
||||
if mapping["sensor"] not in sensor_mappings.keys():
|
||||
sensor_mappings[mapping["sensor"]] = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user