Skip to content

Commit

Permalink
Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aneisch committed May 27, 2024
1 parent 2c32ea6 commit f6d9ba5
Show file tree
Hide file tree
Showing 55 changed files with 1,007 additions and 439 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Build Status](https://github.com/aneisch/home-assistant-config/actions/workflows/check-ha-release-compatibility.yml/badge.svg)](https://github.com/aneisch/home-assistant-config/actions)
[![GitHub last commit](https://img.shields.io/github/last-commit/aneisch/home-assistant-config)](https://github.com/aneisch/home-assistant-config/commits/master)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/aneisch/home-assistant-config)](https://github.com/aneisch/home-assistant-config/graphs/commit-activity)
[![HA Version](https://img.shields.io/badge/Running%20Home%20Assistant-2024.5.2%20(Latest)-brightgreen)](https://github.com/home-assistant/home-assistant/releases/latest)
[![HA Version](https://img.shields.io/badge/Running%20Home%20Assistant-2024.5.5%20(Latest)-brightgreen)](https://github.com/home-assistant/home-assistant/releases/latest)
<br><a href="https://www.buymeacoffee.com/aneisch" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-black.png" width="150px" height="35px" alt="Buy Me A Coffee" style="height: 35px !important;width: 150px !important;" ></a>


Expand Down Expand Up @@ -57,7 +57,7 @@ Also using Grafana/Influx for graphing, both running in Docker containers on NUC
Description | value
-- | --
Lines of ESPHome YAML | 2802
Lines of Home Assistant YAML | 9088
Lines of Home Assistant YAML | 9169
[Integrations](https://www.home-assistant.io/integrations/) in use | 60
Zigbee devices in [`zha`](https://www.home-assistant.io/integrations/zha/) | 26
Z-Wave devices in [`zwave_js`](https://www.home-assistant.io/integrations/zwave_js/) | 37
Expand All @@ -71,10 +71,10 @@ Entities in the [`camera`](https://www.home-assistant.io/components/camera) doma
Entities in the [`climate`](https://www.home-assistant.io/components/climate) domain | 1
Entities in the [`conversation`](https://www.home-assistant.io/components/conversation) domain | 1
Entities in the [`counter`](https://www.home-assistant.io/components/counter) domain | 1
Entities in the [`cover`](https://www.home-assistant.io/components/cover) domain | 13
Entities in the [`cover`](https://www.home-assistant.io/components/cover) domain | 16
Entities in the [`device_tracker`](https://www.home-assistant.io/components/device_tracker) domain | 4
Entities in the [`fan`](https://www.home-assistant.io/components/fan) domain | 3
Entities in the [`group`](https://www.home-assistant.io/components/group) domain | 17
Entities in the [`group`](https://www.home-assistant.io/components/group) domain | 18
Entities in the [`image`](https://www.home-assistant.io/components/image) domain | 7
Entities in the [`input_boolean`](https://www.home-assistant.io/components/input_boolean) domain | 29
Entities in the [`input_datetime`](https://www.home-assistant.io/components/input_datetime) domain | 38
Expand All @@ -90,17 +90,17 @@ Entities in the [`plant`](https://www.home-assistant.io/components/plant) domain
Entities in the [`remote`](https://www.home-assistant.io/components/remote) domain | 1
Entities in the [`script`](https://www.home-assistant.io/components/script) domain | 48
Entities in the [`select`](https://www.home-assistant.io/components/select) domain | 3
Entities in the [`sensor`](https://www.home-assistant.io/components/sensor) domain | 420
Entities in the [`sensor`](https://www.home-assistant.io/components/sensor) domain | 424
Entities in the [`siren`](https://www.home-assistant.io/components/siren) domain | 1
Entities in the [`sun`](https://www.home-assistant.io/components/sun) domain | 1
Entities in the [`switch`](https://www.home-assistant.io/components/switch) domain | 167
Entities in the [`timer`](https://www.home-assistant.io/components/timer) domain | 6
Entities in the [`tts`](https://www.home-assistant.io/components/tts) domain | 1
Entities in the [`update`](https://www.home-assistant.io/components/update) domain | 34
Entities in the [`update`](https://www.home-assistant.io/components/update) domain | 32
Entities in the [`vacuum`](https://www.home-assistant.io/components/vacuum) domain | 1
Entities in the [`weather`](https://www.home-assistant.io/components/weather) domain | 1
Entities in the [`zone`](https://www.home-assistant.io/components/zone) domain | 6
**Total state objects** | **1202**
**Total state objects** | **1208**
## The HACS integrations/plugins that I use:
**Appdaemon**:<br>
[aneisch/follow_me_appdaemon](https://github.com/aneisch/follow_me_appdaemon)<br>
Expand Down
6 changes: 4 additions & 2 deletions automations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
initial_state: true
trigger:
- platform: state
entity_id: sensor.thermostat_latest_equipment_event
entity_id: sensor.thermostat_active_equipment_event
condition: '{{ trigger.to_state.state not in [ ''unavailable'', '''' ] and trigger.from_state.state
not in [ ''unavailable'', '''' ] }}'
action:
Expand Down Expand Up @@ -199,7 +199,7 @@
- lock.garage_exterior_door
- lock.back_door
to: unlocked
condition: '{{ states(''input_boolean.security_status'') == ''on''}}'
condition: '{{ states(''input_boolean.door_notify'') == ''on''}}'
action:
- service: script.notify_wrapper
data:
Expand Down Expand Up @@ -473,6 +473,8 @@
- sensor.office_blind_right_battery
- sensor.guest_bedroom_blind_left_battery
- sensor.guest_bedroom_blind_right_battery
- sensor.master_bedroom_blind_left_battery
- sensor.master_bedroom_blind_right_battery
- sensor.dining_room_blind_left_battery
- sensor.dining_room_blind_center_battery
- sensor.dining_room_blind_right_battery
Expand Down
67 changes: 38 additions & 29 deletions custom_components/monitor_docker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

import asyncio
import logging
import time
import threading
import voluptuous as vol

from datetime import timedelta

import homeassistant.helpers.config_validation as cv

from .helpers import DockerAPI

import voluptuous as vol
from homeassistant.const import (
CONF_MONITORED_CONDITIONS,
CONF_NAME,
CONF_SCAN_INTERVAL,
CONF_URL,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import ConfigType
from homeassistant.helpers.reload import async_setup_reload_service

from .const import (
API,
Expand All @@ -32,20 +29,22 @@
CONF_PRECISION_NETWORK_MB,
CONF_PREFIX,
CONF_RENAME,
CONF_RENAME_ENITITY,
CONF_RETRY,
CONF_SENSORNAME,
CONF_SWITCHENABLED,
CONF_SWITCHNAME,
CONFIG,
CONTAINER_INFO_ALLINONE,
DOMAIN,
DEFAULT_NAME,
DEFAULT_RETRY,
DEFAULT_SENSORNAME,
DEFAULT_SWITCHNAME,
DOMAIN,
MONITORED_CONDITIONS_LIST,
PRECISION,
)
from .helpers import DockerAPI

_LOGGER = logging.getLogger(__name__)

Expand All @@ -57,17 +56,18 @@
vol.Optional(CONF_PREFIX, default=""): cv.string,
vol.Optional(CONF_URL, default=None): vol.Any(cv.string, None),
vol.Optional(CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL): cv.time_period,
vol.Optional(
CONF_MONITORED_CONDITIONS, default=MONITORED_CONDITIONS_LIST
): vol.All(
vol.Optional(CONF_MONITORED_CONDITIONS, default=[]): vol.All(
cv.ensure_list,
[vol.In(MONITORED_CONDITIONS_LIST + list([CONTAINER_INFO_ALLINONE]))],
[vol.In(MONITORED_CONDITIONS_LIST)],
),
vol.Optional(CONF_CONTAINERS, default=[]): cv.ensure_list,
vol.Optional(CONF_CONTAINERS_EXCLUDE, default=[]): cv.ensure_list,
vol.Optional(CONF_RENAME, default={}): dict,
vol.Optional(CONF_RENAME_ENITITY, default=False): cv.boolean,
vol.Optional(CONF_SENSORNAME, default=DEFAULT_SENSORNAME): cv.string,
vol.Optional(CONF_SWITCHENABLED, default=True): cv.boolean,
vol.Optional(CONF_SWITCHENABLED, default=True): vol.Any(
cv.boolean, cv.ensure_list(cv.string)
),
vol.Optional(CONF_SWITCHNAME, default=DEFAULT_SWITCHNAME): cv.string,
vol.Optional(CONF_CERTPATH, default=""): cv.string,
vol.Optional(CONF_RETRY, default=DEFAULT_RETRY): cv.positive_int,
Expand All @@ -88,17 +88,12 @@


#################################################################
async def async_setup(hass, config):
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Will setup the Monitor Docker platform."""

def RunDocker(hass, entry):
async def RunDocker(hass: HomeAssistant, entry: ConfigType) -> None:
"""Wrapper around function for a separated thread."""

# Create out asyncio loop, because we are already inside
# a def (not main) we need to do create/set
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

# Create docker instance, it will have asyncio threads
hass.data[DOMAIN][entry[CONF_NAME]] = {}
hass.data[DOMAIN][entry[CONF_NAME]][CONFIG] = entry
Expand All @@ -109,34 +104,44 @@ def RunDocker(hass, entry):
doLoop = True

try:
hass.data[DOMAIN][entry[CONF_NAME]][API] = DockerAPI(
hass, entry, startCount
)
hass.data[DOMAIN][entry[CONF_NAME]][API] = DockerAPI(hass, entry)
await hass.data[DOMAIN][entry[CONF_NAME]][API].init(startCount)
except Exception as err:
doLoop = False
if entry[CONF_RETRY] == 0:
raise
else:
_LOGGER.error("Failed Docker connect: %s", str(err))
_LOGGER.error("Retry in %d seconds", entry[CONF_RETRY])
time.sleep(entry[CONF_RETRY])
await asyncio.sleep(entry[CONF_RETRY])

startCount += 1

if doLoop:
# Now run forever in this separated thread
loop.run_forever()
# loop.run_forever()

# We only get here if a docker instance disconnected or HASS is stopping
if not hass.data[DOMAIN][entry[CONF_NAME]][API]._dockerStopped:
# If HASS stopped, do not retry
break

# Setup reload service
# await async_setup_reload_service(hass, DOMAIN, [DOMAIN])

# Create domain monitor_docker data variable
hass.data[DOMAIN] = {}

# Now go through all possible entries, we support 1 or more docker hosts (untested)
for entry in config[DOMAIN]:

# Default MONITORED_CONDITIONS_LIST also contains allinone, so we need to fix it up here
if len(entry[CONF_MONITORED_CONDITIONS]) == 0:
# Add whole list, including allinone. Make a copy, no reference
entry[CONF_MONITORED_CONDITIONS] = MONITORED_CONDITIONS_LIST.copy()
# remove the allinone
entry[CONF_MONITORED_CONDITIONS].remove(CONTAINER_INFO_ALLINONE)

# Check if CONF_MONITORED_CONDITIONS has only ALLINONE, then expand to all
if (
len(entry[CONF_MONITORED_CONDITIONS]) == 1
Expand All @@ -154,9 +159,13 @@ def RunDocker(hass, entry):
return False

# Each docker hosts runs in its own thread. We need to pass hass too, for the load_platform
thread = threading.Thread(
target=RunDocker, kwargs={"hass": hass, "entry": entry}
)
thread.start()
asyncio.create_task(RunDocker(hass, entry))

return True


#################################################################
async def async_reset_platform(hass: HomeAssistant, integration_name: str) -> None:
"""Reload the integration."""
if DOMAIN not in hass.data:
_LOGGER.error("monitor_docker not loaded")
Loading

0 comments on commit f6d9ba5

Please sign in to comment.