Code linting
This commit is contained in:
@@ -2,20 +2,23 @@ import logging
|
||||
|
||||
from homeassistant.helpers.entity_registry import (
|
||||
async_entries_for_config_entry,
|
||||
async_entries_for_device
|
||||
async_entries_for_device,
|
||||
)
|
||||
from homeassistant.const import STATE_UNAVAILABLE
|
||||
|
||||
from .const import (
|
||||
DOMAIN, DATA_DEVICES, DATA_ALIASES,
|
||||
USER_COMMANDS, DATA_CONFIG, CONFIG_DEVICES
|
||||
DOMAIN,
|
||||
DATA_DEVICES,
|
||||
DATA_ALIASES,
|
||||
USER_COMMANDS,
|
||||
DATA_CONFIG,
|
||||
CONFIG_DEVICES,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def setup_service(hass):
|
||||
|
||||
def handle_command(call):
|
||||
command = call.data.get("command", None)
|
||||
if not command:
|
||||
@@ -38,23 +41,19 @@ async def setup_service(hass):
|
||||
devices[t].send(command, **data)
|
||||
|
||||
def command_wrapper(call):
|
||||
command = call.service.replace('_', '-')
|
||||
command = call.service.replace("_", "-")
|
||||
call.data = dict(call.data)
|
||||
call.data['command'] = command
|
||||
call.data["command"] = command
|
||||
handle_command(call)
|
||||
|
||||
hass.services.async_register(DOMAIN, 'command', handle_command)
|
||||
hass.services.async_register(DOMAIN, "command", handle_command)
|
||||
for cmd in USER_COMMANDS:
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
cmd.replace('-', '_'),
|
||||
command_wrapper
|
||||
)
|
||||
hass.services.async_register(DOMAIN, cmd.replace("-", "_"), command_wrapper)
|
||||
|
||||
async def call_service(service_call):
|
||||
await async_clean_devices(hass, service_call.data)
|
||||
|
||||
hass.services.async_register(DOMAIN, 'clean_devices', call_service)
|
||||
hass.services.async_register(DOMAIN, "clean_devices", call_service)
|
||||
|
||||
|
||||
async def async_clean_devices(hass, data):
|
||||
@@ -63,14 +62,12 @@ async def async_clean_devices(hass, data):
|
||||
entity_registry = await hass.helpers.entity_registry.async_get_registry()
|
||||
device_registry = await hass.helpers.device_registry.async_get_registry()
|
||||
entity_entries = async_entries_for_config_entry(
|
||||
entity_registry,
|
||||
config_entry.entry_id
|
||||
entity_registry, config_entry.entry_id
|
||||
)
|
||||
|
||||
device_entries = [
|
||||
entry
|
||||
for entry
|
||||
in device_registry.devices.values()
|
||||
for entry in device_registry.devices.values()
|
||||
if config_entry.entry_id in entry.config_entries
|
||||
]
|
||||
|
||||
@@ -103,7 +100,4 @@ async def async_clean_devices(hass, data):
|
||||
|
||||
devices = hass.data[DOMAIN][DATA_DEVICES]
|
||||
for rec in devices:
|
||||
devices[rec].send(
|
||||
'toast',
|
||||
message=f"Removed devices: {removed}"
|
||||
)
|
||||
devices[rec].send("toast", message=f"Removed devices: {removed}")
|
||||
|
||||
Reference in New Issue
Block a user