Remove unneeded dynamic lookup of domain (#59423)
parent
d05c80c8e4
commit
3d909b00d5
homeassistant/components
|
@ -0,0 +1,2 @@
|
|||
"""Constants for the lg_netcast component."""
|
||||
DOMAIN = "lg_netcast"
|
|
@ -31,6 +31,8 @@ from homeassistant.const import (
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
DEFAULT_NAME = "LG TV Remote"
|
||||
|
||||
CONF_ON_ACTION = "turn_on_action"
|
||||
|
@ -69,8 +71,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
|
|||
on_action = config.get(CONF_ON_ACTION)
|
||||
|
||||
client = LgNetCastClient(host, access_token)
|
||||
domain = __name__.split(".")[-2]
|
||||
on_action_script = Script(hass, on_action, name, domain) if on_action else None
|
||||
on_action_script = Script(hass, on_action, name, DOMAIN) if on_action else None
|
||||
|
||||
add_entities([LgTVDevice(client, name, on_action_script)], True)
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity import async_generate_entity_id
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -158,18 +159,17 @@ class AlarmControlPanelTemplate(TemplateEntity, AlarmControlPanelEntity):
|
|||
self._disarm_script = None
|
||||
self._code_arm_required = code_arm_required
|
||||
self._code_format = code_format
|
||||
domain = __name__.split(".")[-2]
|
||||
if disarm_action is not None:
|
||||
self._disarm_script = Script(hass, disarm_action, name, domain)
|
||||
self._disarm_script = Script(hass, disarm_action, name, DOMAIN)
|
||||
self._arm_away_script = None
|
||||
if arm_away_action is not None:
|
||||
self._arm_away_script = Script(hass, arm_away_action, name, domain)
|
||||
self._arm_away_script = Script(hass, arm_away_action, name, DOMAIN)
|
||||
self._arm_home_script = None
|
||||
if arm_home_action is not None:
|
||||
self._arm_home_script = Script(hass, arm_home_action, name, domain)
|
||||
self._arm_home_script = Script(hass, arm_home_action, name, DOMAIN)
|
||||
self._arm_night_script = None
|
||||
if arm_night_action is not None:
|
||||
self._arm_night_script = Script(hass, arm_night_action, name, domain)
|
||||
self._arm_night_script = Script(hass, arm_night_action, name, DOMAIN)
|
||||
|
||||
self._state = None
|
||||
self._unique_id = unique_id
|
||||
|
|
|
@ -40,7 +40,7 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity import async_generate_entity_id
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE, DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -195,21 +195,20 @@ class CoverTemplate(TemplateEntity, CoverEntity):
|
|||
self._tilt_template = tilt_template
|
||||
self._device_class = device_class
|
||||
self._open_script = None
|
||||
domain = __name__.split(".")[-2]
|
||||
if open_action is not None:
|
||||
self._open_script = Script(hass, open_action, friendly_name, domain)
|
||||
self._open_script = Script(hass, open_action, friendly_name, DOMAIN)
|
||||
self._close_script = None
|
||||
if close_action is not None:
|
||||
self._close_script = Script(hass, close_action, friendly_name, domain)
|
||||
self._close_script = Script(hass, close_action, friendly_name, DOMAIN)
|
||||
self._stop_script = None
|
||||
if stop_action is not None:
|
||||
self._stop_script = Script(hass, stop_action, friendly_name, domain)
|
||||
self._stop_script = Script(hass, stop_action, friendly_name, DOMAIN)
|
||||
self._position_script = None
|
||||
if position_action is not None:
|
||||
self._position_script = Script(hass, position_action, friendly_name, domain)
|
||||
self._position_script = Script(hass, position_action, friendly_name, DOMAIN)
|
||||
self._tilt_script = None
|
||||
if tilt_action is not None:
|
||||
self._tilt_script = Script(hass, tilt_action, friendly_name, domain)
|
||||
self._tilt_script = Script(hass, tilt_action, friendly_name, DOMAIN)
|
||||
self._optimistic = optimistic or (not state_template and not position_template)
|
||||
self._tilt_optimistic = tilt_optimistic or not tilt_template
|
||||
self._position = None
|
||||
|
|
|
@ -39,7 +39,7 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity import async_generate_entity_id
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE, DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -209,39 +209,37 @@ class TemplateFan(TemplateEntity, FanEntity):
|
|||
self._direction_template = direction_template
|
||||
self._supported_features = 0
|
||||
|
||||
domain = __name__.split(".")[-2]
|
||||
|
||||
self._on_script = Script(hass, on_action, friendly_name, domain)
|
||||
self._off_script = Script(hass, off_action, friendly_name, domain)
|
||||
self._on_script = Script(hass, on_action, friendly_name, DOMAIN)
|
||||
self._off_script = Script(hass, off_action, friendly_name, DOMAIN)
|
||||
|
||||
self._set_speed_script = None
|
||||
if set_speed_action:
|
||||
self._set_speed_script = Script(
|
||||
hass, set_speed_action, friendly_name, domain
|
||||
hass, set_speed_action, friendly_name, DOMAIN
|
||||
)
|
||||
|
||||
self._set_percentage_script = None
|
||||
if set_percentage_action:
|
||||
self._set_percentage_script = Script(
|
||||
hass, set_percentage_action, friendly_name, domain
|
||||
hass, set_percentage_action, friendly_name, DOMAIN
|
||||
)
|
||||
|
||||
self._set_preset_mode_script = None
|
||||
if set_preset_mode_action:
|
||||
self._set_preset_mode_script = Script(
|
||||
hass, set_preset_mode_action, friendly_name, domain
|
||||
hass, set_preset_mode_action, friendly_name, DOMAIN
|
||||
)
|
||||
|
||||
self._set_oscillating_script = None
|
||||
if set_oscillating_action:
|
||||
self._set_oscillating_script = Script(
|
||||
hass, set_oscillating_action, friendly_name, domain
|
||||
hass, set_oscillating_action, friendly_name, DOMAIN
|
||||
)
|
||||
|
||||
self._set_direction_script = None
|
||||
if set_direction_action:
|
||||
self._set_direction_script = Script(
|
||||
hass, set_direction_action, friendly_name, domain
|
||||
hass, set_direction_action, friendly_name, DOMAIN
|
||||
)
|
||||
|
||||
self._state = STATE_OFF
|
||||
|
|
|
@ -37,7 +37,7 @@ from homeassistant.helpers.config_validation import PLATFORM_SCHEMA
|
|||
from homeassistant.helpers.entity import async_generate_entity_id
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE, DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -211,32 +211,31 @@ class LightTemplate(TemplateEntity, LightEntity):
|
|||
)
|
||||
self._name = friendly_name
|
||||
self._template = state_template
|
||||
domain = __name__.split(".")[-2]
|
||||
self._on_script = Script(hass, on_action, friendly_name, domain)
|
||||
self._off_script = Script(hass, off_action, friendly_name, domain)
|
||||
self._on_script = Script(hass, on_action, friendly_name, DOMAIN)
|
||||
self._off_script = Script(hass, off_action, friendly_name, DOMAIN)
|
||||
self._level_script = None
|
||||
if level_action is not None:
|
||||
self._level_script = Script(hass, level_action, friendly_name, domain)
|
||||
self._level_script = Script(hass, level_action, friendly_name, DOMAIN)
|
||||
self._level_template = level_template
|
||||
self._temperature_script = None
|
||||
if temperature_action is not None:
|
||||
self._temperature_script = Script(
|
||||
hass, temperature_action, friendly_name, domain
|
||||
hass, temperature_action, friendly_name, DOMAIN
|
||||
)
|
||||
self._temperature_template = temperature_template
|
||||
self._color_script = None
|
||||
if color_action is not None:
|
||||
self._color_script = Script(hass, color_action, friendly_name, domain)
|
||||
self._color_script = Script(hass, color_action, friendly_name, DOMAIN)
|
||||
self._color_template = color_template
|
||||
self._white_value_script = None
|
||||
if white_value_action is not None:
|
||||
self._white_value_script = Script(
|
||||
hass, white_value_action, friendly_name, domain
|
||||
hass, white_value_action, friendly_name, DOMAIN
|
||||
)
|
||||
self._white_value_template = white_value_template
|
||||
self._effect_script = None
|
||||
if effect_action is not None:
|
||||
self._effect_script = Script(hass, effect_action, friendly_name, domain)
|
||||
self._effect_script = Script(hass, effect_action, friendly_name, DOMAIN)
|
||||
self._effect_list_template = effect_list_template
|
||||
self._effect_template = effect_template
|
||||
self._max_mireds_template = max_mireds_template
|
||||
|
|
|
@ -22,7 +22,7 @@ from homeassistant.exceptions import TemplateError
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE, DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
|
||||
CONF_LOCK = "lock"
|
||||
|
@ -88,9 +88,8 @@ class TemplateLock(TemplateEntity, LockEntity):
|
|||
self._state = None
|
||||
self._name = name
|
||||
self._state_template = value_template
|
||||
domain = __name__.split(".")[-2]
|
||||
self._command_lock = Script(hass, command_lock, name, domain)
|
||||
self._command_unlock = Script(hass, command_unlock, name, domain)
|
||||
self._command_lock = Script(hass, command_lock, name, DOMAIN)
|
||||
self._command_unlock = Script(hass, command_unlock, name, DOMAIN)
|
||||
self._optimistic = optimistic
|
||||
self._unique_id = unique_id
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.script import Script
|
||||
from homeassistant.helpers.template import Template, TemplateError
|
||||
|
||||
from .const import CONF_AVAILABILITY
|
||||
from .const import CONF_AVAILABILITY, DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
from .trigger_entity import TriggerEntity
|
||||
|
||||
|
@ -139,9 +139,8 @@ class TemplateNumber(TemplateEntity, NumberEntity):
|
|||
with contextlib.suppress(TemplateError):
|
||||
self._attr_name = name_template.async_render(parse_result=False)
|
||||
self._value_template = value_template
|
||||
domain = __name__.split(".")[-2]
|
||||
self._command_set_value = Script(
|
||||
hass, command_set_value, self._attr_name, domain
|
||||
hass, command_set_value, self._attr_name, DOMAIN
|
||||
)
|
||||
self._step_template = step_template
|
||||
self._min_value_template = minimum_template
|
||||
|
@ -212,12 +211,11 @@ class TriggerNumberEntity(TriggerEntity, NumberEntity):
|
|||
) -> None:
|
||||
"""Initialize the entity."""
|
||||
super().__init__(hass, coordinator, config)
|
||||
domain = __name__.split(".")[-2]
|
||||
self._command_set_value = Script(
|
||||
hass,
|
||||
config[CONF_SET_VALUE],
|
||||
self._rendered.get(CONF_NAME, DEFAULT_NAME),
|
||||
domain,
|
||||
DOMAIN,
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -27,7 +27,7 @@ from homeassistant.helpers.script import Script
|
|||
from homeassistant.helpers.template import Template, TemplateError
|
||||
|
||||
from . import TriggerUpdateCoordinator
|
||||
from .const import CONF_AVAILABILITY
|
||||
from .const import CONF_AVAILABILITY, DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
from .trigger_entity import TriggerEntity
|
||||
|
||||
|
@ -129,9 +129,8 @@ class TemplateSelect(TemplateEntity, SelectEntity):
|
|||
self._attr_name = name_template.async_render(parse_result=False)
|
||||
self._name_template = name_template
|
||||
self._value_template = value_template
|
||||
domain = __name__.split(".")[-2]
|
||||
self._command_select_option = Script(
|
||||
hass, command_select_option, self._attr_name, domain
|
||||
hass, command_select_option, self._attr_name, DOMAIN
|
||||
)
|
||||
self._options_template = options_template
|
||||
self._attr_assumed_state = self._optimistic = optimistic
|
||||
|
@ -182,12 +181,11 @@ class TriggerSelectEntity(TriggerEntity, SelectEntity):
|
|||
) -> None:
|
||||
"""Initialize the entity."""
|
||||
super().__init__(hass, coordinator, config)
|
||||
domain = __name__.split(".")[-2]
|
||||
self._command_select_option = Script(
|
||||
hass,
|
||||
config[CONF_SELECT_OPTION],
|
||||
self._rendered.get(CONF_NAME, DEFAULT_NAME),
|
||||
domain,
|
||||
DOMAIN,
|
||||
)
|
||||
|
||||
@property
|
||||
|
|
|
@ -25,7 +25,7 @@ from homeassistant.helpers.entity import async_generate_entity_id
|
|||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE, DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
|
||||
_VALID_STATES = [STATE_ON, STATE_OFF, "true", "false"]
|
||||
|
@ -119,9 +119,8 @@ class SwitchTemplate(TemplateEntity, SwitchEntity, RestoreEntity):
|
|||
)
|
||||
self._name = friendly_name
|
||||
self._template = state_template
|
||||
domain = __name__.split(".")[-2]
|
||||
self._on_script = Script(hass, on_action, friendly_name, domain)
|
||||
self._off_script = Script(hass, off_action, friendly_name, domain)
|
||||
self._on_script = Script(hass, on_action, friendly_name, DOMAIN)
|
||||
self._off_script = Script(hass, off_action, friendly_name, DOMAIN)
|
||||
self._state = False
|
||||
self._unique_id = unique_id
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity import async_generate_entity_id
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE
|
||||
from .const import CONF_AVAILABILITY_TEMPLATE, DOMAIN
|
||||
from .template_entity import TemplateEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -187,43 +187,41 @@ class TemplateVacuum(TemplateEntity, StateVacuumEntity):
|
|||
self._fan_speed_template = fan_speed_template
|
||||
self._supported_features = SUPPORT_START
|
||||
|
||||
domain = __name__.split(".")[-2]
|
||||
|
||||
self._start_script = Script(hass, start_action, friendly_name, domain)
|
||||
self._start_script = Script(hass, start_action, friendly_name, DOMAIN)
|
||||
|
||||
self._pause_script = None
|
||||
if pause_action:
|
||||
self._pause_script = Script(hass, pause_action, friendly_name, domain)
|
||||
self._pause_script = Script(hass, pause_action, friendly_name, DOMAIN)
|
||||
self._supported_features |= SUPPORT_PAUSE
|
||||
|
||||
self._stop_script = None
|
||||
if stop_action:
|
||||
self._stop_script = Script(hass, stop_action, friendly_name, domain)
|
||||
self._stop_script = Script(hass, stop_action, friendly_name, DOMAIN)
|
||||
self._supported_features |= SUPPORT_STOP
|
||||
|
||||
self._return_to_base_script = None
|
||||
if return_to_base_action:
|
||||
self._return_to_base_script = Script(
|
||||
hass, return_to_base_action, friendly_name, domain
|
||||
hass, return_to_base_action, friendly_name, DOMAIN
|
||||
)
|
||||
self._supported_features |= SUPPORT_RETURN_HOME
|
||||
|
||||
self._clean_spot_script = None
|
||||
if clean_spot_action:
|
||||
self._clean_spot_script = Script(
|
||||
hass, clean_spot_action, friendly_name, domain
|
||||
hass, clean_spot_action, friendly_name, DOMAIN
|
||||
)
|
||||
self._supported_features |= SUPPORT_CLEAN_SPOT
|
||||
|
||||
self._locate_script = None
|
||||
if locate_action:
|
||||
self._locate_script = Script(hass, locate_action, friendly_name, domain)
|
||||
self._locate_script = Script(hass, locate_action, friendly_name, DOMAIN)
|
||||
self._supported_features |= SUPPORT_LOCATE
|
||||
|
||||
self._set_fan_speed_script = None
|
||||
if set_fan_speed_action:
|
||||
self._set_fan_speed_script = Script(
|
||||
hass, set_fan_speed_action, friendly_name, domain
|
||||
hass, set_fan_speed_action, friendly_name, DOMAIN
|
||||
)
|
||||
self._supported_features |= SUPPORT_FAN_SPEED
|
||||
|
||||
|
|
|
@ -8,9 +8,9 @@ import wakeonlan
|
|||
from homeassistant.const import CONF_BROADCAST_ADDRESS, CONF_BROADCAST_PORT, CONF_MAC
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
from .const import DOMAIN
|
||||
|
||||
DOMAIN = "wake_on_lan"
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
SERVICE_SEND_MAGIC_PACKET = "send_magic_packet"
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
"""Constants for the Wake-On-LAN component."""
|
||||
DOMAIN = "wake_on_lan"
|
|
@ -18,6 +18,8 @@ from homeassistant.helpers import device_registry as dr
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.script import Script
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_OFF_ACTION = "turn_off"
|
||||
|
@ -82,9 +84,8 @@ class WolSwitch(SwitchEntity):
|
|||
self._mac_address = mac_address
|
||||
self._broadcast_address = broadcast_address
|
||||
self._broadcast_port = broadcast_port
|
||||
domain = __name__.split(".")[-2]
|
||||
self._off_script = (
|
||||
Script(hass, off_action, name, domain) if off_action else None
|
||||
Script(hass, off_action, name, DOMAIN) if off_action else None
|
||||
)
|
||||
self._state = False
|
||||
self._assumed_state = host is None
|
||||
|
|
Loading…
Reference in New Issue