Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -8,17 +8,28 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from .common import async_process_devices
|
||||
from .config_flow import configured_instances
|
||||
from .const import (DOMAIN, VS_DISPATCHERS, VS_DISCOVERY, VS_SWITCHES,
|
||||
SERVICE_UPDATE_DEVS, VS_MANAGER)
|
||||
from .const import (
|
||||
DOMAIN,
|
||||
VS_DISPATCHERS,
|
||||
VS_DISCOVERY,
|
||||
VS_SWITCHES,
|
||||
SERVICE_UPDATE_DEVS,
|
||||
VS_MANAGER,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema({
|
||||
DOMAIN: vol.Schema({
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
}),
|
||||
}, extra=vol.ALLOW_EXTRA)
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string,
|
||||
}
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
@@ -32,11 +43,13 @@ async def async_setup(hass, config):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={'source': SOURCE_IMPORT},
|
||||
context={"source": SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_USERNAME: conf[CONF_USERNAME],
|
||||
CONF_PASSWORD: conf[CONF_PASSWORD]
|
||||
}))
|
||||
CONF_PASSWORD: conf[CONF_PASSWORD],
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@@ -69,7 +82,7 @@ async def async_setup_entry(hass, config_entry):
|
||||
|
||||
if device_dict[VS_SWITCHES]:
|
||||
switches.extend(device_dict[VS_SWITCHES])
|
||||
hass.async_create_task(forward_setup(config_entry, 'switch'))
|
||||
hass.async_create_task(forward_setup(config_entry, "switch"))
|
||||
|
||||
async def async_new_device_discovery(service):
|
||||
"""Discover if new devices should be added."""
|
||||
@@ -83,18 +96,15 @@ async def async_setup_entry(hass, config_entry):
|
||||
new_switches = list(switch_set.difference(switches))
|
||||
if new_switches and switches:
|
||||
switches.extend(new_switches)
|
||||
async_dispatcher_send(hass,
|
||||
VS_DISCOVERY.format(VS_SWITCHES),
|
||||
new_switches)
|
||||
async_dispatcher_send(hass, VS_DISCOVERY.format(VS_SWITCHES), new_switches)
|
||||
return
|
||||
if new_switches and not switches:
|
||||
switches.extend(new_switches)
|
||||
hass.async_create_task(forward_setup(config_entry, 'switch'))
|
||||
hass.async_create_task(forward_setup(config_entry, "switch"))
|
||||
|
||||
hass.services.async_register(DOMAIN,
|
||||
SERVICE_UPDATE_DEVS,
|
||||
async_new_device_discovery
|
||||
)
|
||||
hass.services.async_register(
|
||||
DOMAIN, SERVICE_UPDATE_DEVS, async_new_device_discovery
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
@@ -104,7 +114,7 @@ async def async_unload_entry(hass, entry):
|
||||
forward_unload = hass.config_entries.async_forward_entry_unload
|
||||
remove_switches = False
|
||||
if hass.data[DOMAIN][VS_SWITCHES]:
|
||||
remove_switches = await forward_unload(entry, 'switch')
|
||||
remove_switches = await forward_unload(entry, "switch")
|
||||
|
||||
if remove_switches:
|
||||
hass.services.async_remove(DOMAIN, SERVICE_UPDATE_DEVS)
|
||||
|
||||
Reference in new issue
Block a user