From a1c1cfec6979924d65060af15b68538253624b16 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 16 Oct 2022 21:26:34 +0200 Subject: [PATCH 1/2] Adding home assistant clients binary sensors --- app/scheduler_tasks.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/scheduler_tasks.py b/app/scheduler_tasks.py index 62a03a3..64d30c6 100644 --- a/app/scheduler_tasks.py +++ b/app/scheduler_tasks.py @@ -24,8 +24,8 @@ def scheduler_tasks_update_sync_status(app): c_status.update_sync_status(sync_status) -def scheduler_tasks_home_assistant_post(sensor_name, data): - url = f"{home_assistant_url}/api/states/sensor.unicloud_{sensor_name}" +def scheduler_tasks_home_assistant_post(sensor_name, data, domain="sensor"): + url = f"{home_assistant_url}/api/states/{domain}.unicloud_{sensor_name}" headers = { 'Authorization': f'Bearer {home_assistant_token}', 'content-type': 'application/json', @@ -67,6 +67,12 @@ def scheduler_tasks_update_home_assistant_clients(app): "Sync_Ok": client_info['ok'], "Sync_Ko": client_info['ko'], "Sync_Threshold": client_info['threshold'], "Sync_Total": client_info['total']}} scheduler_tasks_home_assistant_post(sensor_name, data) + if sync_status == "In Sync": + binary_status = "off" + else: + binary_status = "on" + data = {f"state": binary_status, "attributes": {"device_class": "problem"}} + scheduler_tasks_home_assistant_post(sensor_name, data, "binary_sensor") def scheduler_tasks_update_home_assistant_shares(app): From 443093823ddfe896e67aa784df5137a9bc40551a Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Mon, 17 Oct 2022 11:24:11 +0200 Subject: [PATCH 2/2] Adding home assistant clients binary sensors --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2e4c486..1ece0e6 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Please read volume persistent requirements: - **Do not run docker/docker-compose as root, app will exit!!** **As docker best practice, add your user to docker group instead with `usermod -a -G docker `** -- **Make sure default userid(1000) is a system valid id with read/write permission on persistent volumes, if not change `USER_UID` env var on docker-compose.yml** +- **Make sure default userid(1000) is a system valid id with read/write permission on persistent volumes, if not change `USER_UID` env var on docker-compose.yml** **On linux run command `id` to get your user id**
Before you can start using this tool you might want to test locally with [docker-compose](https://docs.docker.com/compose/install/). @@ -216,10 +216,10 @@ You can decide how many events logs you want to keep with *MAX_LOG_EVENTS* var, Why? Just because it's cool :-) I use home assistant for a lot of stuff so I wanted to have unicloud as entities on HA. I didn't have time so far to create a real integration, maybe I will consider it for the future if useful. -As for now client/server/shares infos are published at a custom interval (HOME_ASSITANT_PUSH_INTERVAL). +As for now client/server/shares infos are published at a custom interval (HOME_ASSITANT_PUSH_INTERVAL). +Clients have also binary_sensors for replica sync status (InSync/OutOfSync). Configuration is simple, make sure you have a token and fillup all 4 HOME_ASSISTANT_* ENV VARS. - This is the result on home assistant.