async states
This commit is contained in:
@@ -3,14 +3,13 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.helpers import discovery
|
||||
from homeassistant.components.hassio import (
|
||||
async_get_addon_info,
|
||||
get_addons_info,
|
||||
)
|
||||
from homeassistant.const import CONF_INTERNAL_URL
|
||||
|
||||
DOMAIN = "airsend"
|
||||
AS_TYPE = ["switch", "cover", "button"]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType):
|
||||
"""Set up the AirSend component."""
|
||||
if DOMAIN not in config:
|
||||
@@ -22,12 +21,16 @@ async def async_setup(hass: HomeAssistant, config: ConfigType):
|
||||
pass
|
||||
if internalurl == "":
|
||||
try:
|
||||
addon_info: dict = await async_get_addon_info(hass, "local_airsend")
|
||||
ip = addon_info["ip_address"]
|
||||
if ip:
|
||||
internalurl = "http://" + str(ip) + ":33863/"
|
||||
except KeyError:
|
||||
addons_info = get_addons_info(hass)
|
||||
for name, options in addons_info.items():
|
||||
if "_airsend" in name:
|
||||
ip = options["ip_address"]
|
||||
if ip:
|
||||
internalurl = "http://" + str(ip) + ":33863/"
|
||||
except:
|
||||
pass
|
||||
if internalurl != "" and not internalurl.endswith('/'):
|
||||
internalurl += "/"
|
||||
config[DOMAIN][CONF_INTERNAL_URL] = internalurl
|
||||
for plateform in AS_TYPE:
|
||||
discovery.load_platform(hass, plateform, DOMAIN, config[DOMAIN].copy(), config)
|
||||
|
||||
Reference in New Issue
Block a user