Use HOMEASSISTANT_DOMAIN alias for core DOMAIN (#122760)

This commit is contained in:
epenet 2024-07-29 13:35:36 +02:00 committed by GitHub
parent 9ce7779bde
commit 07c7bb8b2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 70 additions and 59 deletions

View file

@ -21,7 +21,7 @@ from homeassistant.const import (
CONF_PATH,
__version__,
)
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant, callback
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.util import yaml
@ -372,7 +372,7 @@ class DomainBlueprints:
shutil.copytree(
integration.file_path / BLUEPRINT_FOLDER,
self.blueprint_folder / HA_DOMAIN,
self.blueprint_folder / HOMEASSISTANT_DOMAIN,
)
await self.hass.async_add_executor_job(populate)

View file

@ -11,7 +11,7 @@ from homeassistant.components.scene import (
)
from homeassistant.config import SCENE_CONFIG_PATH
from homeassistant.const import CONF_ID, SERVICE_RELOAD
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant, callback
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, entity_registry as er
from .const import ACTION_DELETE
@ -32,7 +32,9 @@ def async_setup(hass: HomeAssistant) -> bool:
ent_reg = er.async_get(hass)
entity_id = ent_reg.async_get_entity_id(DOMAIN, HA_DOMAIN, config_key)
entity_id = ent_reg.async_get_entity_id(
DOMAIN, HOMEASSISTANT_DOMAIN, config_key
)
if entity_id is None:
return

View file

@ -33,7 +33,7 @@ from homeassistant.const import (
STATE_UNKNOWN,
)
from homeassistant.core import (
DOMAIN as HA_DOMAIN,
DOMAIN as HOMEASSISTANT_DOMAIN,
Event,
EventStateChangedData,
HomeAssistant,
@ -554,12 +554,14 @@ class GenericHygrostat(HumidifierEntity, RestoreEntity):
async def _async_device_turn_on(self) -> None:
"""Turn humidifier toggleable device on."""
data = {ATTR_ENTITY_ID: self._switch_entity_id}
await self.hass.services.async_call(HA_DOMAIN, SERVICE_TURN_ON, data)
await self.hass.services.async_call(HOMEASSISTANT_DOMAIN, SERVICE_TURN_ON, data)
async def _async_device_turn_off(self) -> None:
"""Turn humidifier toggleable device off."""
data = {ATTR_ENTITY_ID: self._switch_entity_id}
await self.hass.services.async_call(HA_DOMAIN, SERVICE_TURN_OFF, data)
await self.hass.services.async_call(
HOMEASSISTANT_DOMAIN, SERVICE_TURN_OFF, data
)
async def async_set_mode(self, mode: str) -> None:
"""Set new mode.

View file

@ -38,7 +38,7 @@ from homeassistant.const import (
UnitOfTemperature,
)
from homeassistant.core import (
DOMAIN as HA_DOMAIN,
DOMAIN as HOMEASSISTANT_DOMAIN,
CoreState,
Event,
EventStateChangedData,
@ -570,14 +570,14 @@ class GenericThermostat(ClimateEntity, RestoreEntity):
"""Turn heater toggleable device on."""
data = {ATTR_ENTITY_ID: self.heater_entity_id}
await self.hass.services.async_call(
HA_DOMAIN, SERVICE_TURN_ON, data, context=self._context
HOMEASSISTANT_DOMAIN, SERVICE_TURN_ON, data, context=self._context
)
async def _async_heater_turn_off(self) -> None:
"""Turn heater toggleable device off."""
data = {ATTR_ENTITY_ID: self.heater_entity_id}
await self.hass.services.async_call(
HA_DOMAIN, SERVICE_TURN_OFF, data, context=self._context
HOMEASSISTANT_DOMAIN, SERVICE_TURN_OFF, data, context=self._context
)
async def async_set_preset_mode(self, preset_mode: str) -> None:

View file

@ -81,7 +81,7 @@ from homeassistant.const import (
STATE_UNKNOWN,
UnitOfTemperature,
)
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.helpers.network import get_url
from homeassistant.util import color as color_util, dt as dt_util
from homeassistant.util.dt import utcnow
@ -511,7 +511,7 @@ class OnOffTrait(_Trait):
async def execute(self, command, data, params, challenge):
"""Execute an OnOff command."""
if (domain := self.state.domain) == group.DOMAIN:
service_domain = HA_DOMAIN
service_domain = HOMEASSISTANT_DOMAIN
service = SERVICE_TURN_ON if params["on"] else SERVICE_TURN_OFF
else:

View file

@ -24,7 +24,7 @@ from homeassistant.const import (
STATE_ON,
)
from homeassistant.core import (
DOMAIN as HA_DOMAIN,
DOMAIN as HOMEASSISTANT_DOMAIN,
HomeAssistant,
ServiceCall,
State,
@ -92,7 +92,7 @@ STATES_SCHEMA = vol.All(dict, _convert_states)
PLATFORM_SCHEMA = vol.Schema(
{
vol.Required(CONF_PLATFORM): HA_DOMAIN,
vol.Required(CONF_PLATFORM): HOMEASSISTANT_DOMAIN,
vol.Required(STATES): vol.All(
cv.ensure_list,
[
@ -206,7 +206,7 @@ async def async_setup_platform(
# Extract only the config for the Home Assistant platform, ignore the rest.
for p_type, p_config in conf_util.config_per_platform(conf, SCENE_DOMAIN):
if p_type != HA_DOMAIN:
if p_type != HOMEASSISTANT_DOMAIN:
continue
_process_scenes_config(hass, async_add_entities, p_config)

View file

@ -1,32 +1,32 @@
"""Exceptions raised by Intergas InComfort integration."""
from homeassistant.core import DOMAIN
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
from homeassistant.exceptions import ConfigEntryNotReady, HomeAssistantError
class NotFound(HomeAssistantError):
"""Raise exception if no Lan2RF Gateway was found."""
translation_domain = DOMAIN
translation_domain = HOMEASSISTANT_DOMAIN
translation_key = "not_found"
class NoHeaters(ConfigEntryNotReady):
"""Raise exception if no heaters are found."""
translation_domain = DOMAIN
translation_domain = HOMEASSISTANT_DOMAIN
translation_key = "no_heaters"
class InConfortTimeout(ConfigEntryNotReady):
"""Raise exception if no heaters are found."""
translation_domain = DOMAIN
translation_domain = HOMEASSISTANT_DOMAIN
translation_key = "timeout_error"
class InConfortUnknownError(ConfigEntryNotReady):
"""Raise exception if no heaters are found."""
translation_domain = DOMAIN
translation_domain = HOMEASSISTANT_DOMAIN
translation_key = "unknown"

View file

@ -35,7 +35,7 @@ from homeassistant.const import (
SERVICE_TURN_OFF,
SERVICE_TURN_ON,
)
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant, State
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, State
from homeassistant.helpers import config_validation as cv, integration_platform, intent
from homeassistant.helpers.typing import ConfigType
@ -82,7 +82,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass,
OnOffIntentHandler(
intent.INTENT_TURN_ON,
HA_DOMAIN,
HOMEASSISTANT_DOMAIN,
SERVICE_TURN_ON,
description="Turns on/opens a device or entity",
),
@ -91,7 +91,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass,
OnOffIntentHandler(
intent.INTENT_TURN_OFF,
HA_DOMAIN,
HOMEASSISTANT_DOMAIN,
SERVICE_TURN_OFF,
description="Turns off/closes a device or entity",
),
@ -100,7 +100,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
hass,
intent.ServiceIntentHandler(
intent.INTENT_TOGGLE,
HA_DOMAIN,
HOMEASSISTANT_DOMAIN,
SERVICE_TOGGLE,
description="Toggles a device or entity",
),

View file

@ -1,7 +1,7 @@
"""Base entity for the Ping component."""
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import DOMAIN
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -24,6 +24,6 @@ class PingEntity(CoordinatorEntity[PingUpdateCoordinator]):
self._attr_unique_id = unique_id
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, config_entry.entry_id)},
identifiers={(HOMEASSISTANT_DOMAIN, config_entry.entry_id)},
manufacturer="Ping",
)

View file

@ -12,7 +12,7 @@ import voluptuous as vol
from homeassistant.components.light import ATTR_TRANSITION
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_PLATFORM, SERVICE_TURN_ON, STATE_UNAVAILABLE
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.helpers.typing import ConfigType
@ -25,7 +25,7 @@ STATES: Final = "states"
def _hass_domain_validator(config: dict[str, Any]) -> dict[str, Any]:
"""Validate platform in config for homeassistant domain."""
if CONF_PLATFORM not in config:
config = {CONF_PLATFORM: HA_DOMAIN, STATES: config}
config = {CONF_PLATFORM: HOMEASSISTANT_DOMAIN, STATES: config}
return config
@ -67,7 +67,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
await component.async_setup(config)
# Ensure Home Assistant platform always loaded.
hass.async_create_task(
component.async_setup_platform(HA_DOMAIN, {"platform": HA_DOMAIN, STATES: []}),
component.async_setup_platform(
HOMEASSISTANT_DOMAIN, {"platform": HOMEASSISTANT_DOMAIN, STATES: []}
),
eager_start=True,
)
component.async_register_entity_service(

View file

@ -1,6 +1,6 @@
"""Base entity for Streamlabs integration."""
from homeassistant.core import DOMAIN
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -23,7 +23,8 @@ class StreamlabsWaterEntity(CoordinatorEntity[StreamlabsCoordinator]):
self._location_id = location_id
self._attr_unique_id = f"{location_id}-{key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, location_id)}, name=self.location_data.name
identifiers={(HOMEASSISTANT_DOMAIN, location_id)},
name=self.location_data.name,
)
@property

View file

@ -60,7 +60,7 @@ from .const import (
LEGACY_CONF_WHITELIST_EXTERNAL_DIRS,
__version__,
)
from .core import DOMAIN as HA_DOMAIN, ConfigSource, HomeAssistant, callback
from .core import DOMAIN as HOMEASSISTANT_DOMAIN, ConfigSource, HomeAssistant, callback
from .exceptions import ConfigValidationError, HomeAssistantError
from .generated.currencies import HISTORIC_CURRENCIES
from .helpers import config_validation as cv, issue_registry as ir
@ -261,12 +261,12 @@ CUSTOMIZE_CONFIG_SCHEMA = vol.Schema(
def _raise_issue_if_historic_currency(hass: HomeAssistant, currency: str) -> None:
if currency not in HISTORIC_CURRENCIES:
ir.async_delete_issue(hass, HA_DOMAIN, "historic_currency")
ir.async_delete_issue(hass, HOMEASSISTANT_DOMAIN, "historic_currency")
return
ir.async_create_issue(
hass,
HA_DOMAIN,
HOMEASSISTANT_DOMAIN,
"historic_currency",
is_fixable=False,
learn_more_url="homeassistant://config/general",
@ -278,12 +278,12 @@ def _raise_issue_if_historic_currency(hass: HomeAssistant, currency: str) -> Non
def _raise_issue_if_no_country(hass: HomeAssistant, country: str | None) -> None:
if country is not None:
ir.async_delete_issue(hass, HA_DOMAIN, "country_not_configured")
ir.async_delete_issue(hass, HOMEASSISTANT_DOMAIN, "country_not_configured")
return
ir.async_create_issue(
hass,
HA_DOMAIN,
HOMEASSISTANT_DOMAIN,
"country_not_configured",
is_fixable=False,
learn_more_url="homeassistant://config/general",
@ -481,12 +481,14 @@ async def async_hass_config_yaml(hass: HomeAssistant) -> dict:
for invalid_domain in invalid_domains:
config.pop(invalid_domain)
core_config = config.get(HA_DOMAIN, {})
core_config = config.get(HOMEASSISTANT_DOMAIN, {})
try:
await merge_packages_config(hass, config, core_config.get(CONF_PACKAGES, {}))
except vol.Invalid as exc:
suffix = ""
if annotation := find_annotation(config, [HA_DOMAIN, CONF_PACKAGES, *exc.path]):
if annotation := find_annotation(
config, [HOMEASSISTANT_DOMAIN, CONF_PACKAGES, *exc.path]
):
suffix = f" at {_relpath(hass, annotation[0])}, line {annotation[1]}"
_LOGGER.error(
"Invalid package configuration '%s'%s: %s", CONF_PACKAGES, suffix, exc
@ -709,7 +711,7 @@ def stringify_invalid(
)
else:
message_prefix = f"Invalid config for '{domain}'"
if domain != HA_DOMAIN and link:
if domain != HOMEASSISTANT_DOMAIN and link:
message_suffix = f", please check the docs at {link}"
else:
message_suffix = ""
@ -792,7 +794,7 @@ def format_homeassistant_error(
if annotation := find_annotation(config, [domain]):
message_prefix += f" at {_relpath(hass, annotation[0])}, line {annotation[1]}"
message = f"{message_prefix}: {str(exc) or repr(exc)}"
if domain != HA_DOMAIN and link:
if domain != HOMEASSISTANT_DOMAIN and link:
message += f", please check the docs at {link}"
return message
@ -916,7 +918,7 @@ async def async_process_ha_core_config(hass: HomeAssistant, config: dict) -> Non
cust_glob = OrderedDict(config[CONF_CUSTOMIZE_GLOB])
for name, pkg in config[CONF_PACKAGES].items():
if (pkg_cust := pkg.get(HA_DOMAIN)) is None:
if (pkg_cust := pkg.get(HOMEASSISTANT_DOMAIN)) is None:
continue
try:
@ -940,7 +942,9 @@ def _log_pkg_error(
) -> None:
"""Log an error while merging packages."""
message_prefix = f"Setup of package '{package}'"
if annotation := find_annotation(config, [HA_DOMAIN, CONF_PACKAGES, package]):
if annotation := find_annotation(
config, [HOMEASSISTANT_DOMAIN, CONF_PACKAGES, package]
):
message_prefix += f" at {_relpath(hass, annotation[0])}, line {annotation[1]}"
_LOGGER.error("%s failed: %s", message_prefix, message)
@ -1055,7 +1059,7 @@ async def merge_packages_config(
continue
for comp_name, comp_conf in pack_conf.items():
if comp_name == HA_DOMAIN:
if comp_name == HOMEASSISTANT_DOMAIN:
continue
try:
domain = cv.domain_key(comp_name)
@ -1200,7 +1204,7 @@ def _get_log_message_and_stack_print_pref(
# Generate the log message from the English translations
log_message = async_get_exception_message(
HA_DOMAIN,
HOMEASSISTANT_DOMAIN,
platform_exception.translation_key,
translation_placeholders=placeholders,
)
@ -1261,7 +1265,7 @@ def async_drop_config_annotations(
# Don't drop annotations from the homeassistant integration because it may
# have configuration for other integrations as packages.
if integration.domain in config and integration.domain != HA_DOMAIN:
if integration.domain in config and integration.domain != HOMEASSISTANT_DOMAIN:
drop_config_annotations_rec(config[integration.domain])
return config
@ -1313,7 +1317,7 @@ def async_handle_component_errors(
raise ConfigValidationError(
translation_key,
[platform_exception.exception for platform_exception in config_exception_info],
translation_domain=HA_DOMAIN,
translation_domain=HOMEASSISTANT_DOMAIN,
translation_placeholders=placeholders,
)

View file

@ -31,7 +31,7 @@ from .components import persistent_notification
from .const import EVENT_HOMEASSISTANT_STARTED, EVENT_HOMEASSISTANT_STOP, Platform
from .core import (
CALLBACK_TYPE,
DOMAIN as HA_DOMAIN,
DOMAIN as HOMEASSISTANT_DOMAIN,
CoreState,
Event,
HassJob,
@ -1049,7 +1049,7 @@ class ConfigEntry(Generic[_DataT]):
issue_id = f"config_entry_reauth_{self.domain}_{self.entry_id}"
ir.async_create_issue(
hass,
HA_DOMAIN,
HOMEASSISTANT_DOMAIN,
issue_id,
data={"flow_id": result["flow_id"]},
is_fixable=False,
@ -1254,7 +1254,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager[ConfigFlowResult]):
flow_id=flow_id,
handler=handler,
reason="single_instance_allowed",
translation_domain=HA_DOMAIN,
translation_domain=HOMEASSISTANT_DOMAIN,
)
loop = self.hass.loop
@ -1343,7 +1343,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager[ConfigFlowResult]):
entry := self.config_entries.async_get_entry(entry_id)
) is not None:
issue_id = f"config_entry_reauth_{entry.domain}_{entry.entry_id}"
ir.async_delete_issue(self.hass, HA_DOMAIN, issue_id)
ir.async_delete_issue(self.hass, HOMEASSISTANT_DOMAIN, issue_id)
if result["type"] != data_entry_flow.FlowResultType.CREATE_ENTRY:
return result
@ -1360,7 +1360,7 @@ class ConfigEntriesFlowManager(data_entry_flow.FlowManager[ConfigFlowResult]):
flow_id=flow.flow_id,
handler=flow.handler,
reason="single_instance_allowed",
translation_domain=HA_DOMAIN,
translation_domain=HOMEASSISTANT_DOMAIN,
)
# Check if config entry exists with unique ID. Unload it.
@ -1752,7 +1752,7 @@ class ConfigEntries:
if "flow_id" in progress_flow:
self.hass.config_entries.flow.async_abort(progress_flow["flow_id"])
issue_id = f"config_entry_reauth_{entry.domain}_{entry.entry_id}"
ir.async_delete_issue(self.hass, HA_DOMAIN, issue_id)
ir.async_delete_issue(self.hass, HOMEASSISTANT_DOMAIN, issue_id)
# After we have fully removed an "ignore" config entry we can try and rediscover
# it so that a user is able to immediately start configuring it. We do this by

View file

@ -22,7 +22,7 @@ from homeassistant.config import ( # type: ignore[attr-defined]
load_yaml_config_file,
merge_packages_config,
)
from homeassistant.core import DOMAIN as HA_DOMAIN, HomeAssistant
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
from homeassistant.exceptions import HomeAssistantError
from homeassistant.requirements import (
RequirementsNotFound,
@ -157,10 +157,10 @@ async def async_check_ha_config_file( # noqa: C901
return result.add_error(f"Error loading {config_path}: {err}")
# Extract and validate core [homeassistant] config
core_config = config.pop(HA_DOMAIN, {})
core_config = config.pop(HOMEASSISTANT_DOMAIN, {})
try:
core_config = CORE_CONFIG_SCHEMA(core_config)
result[HA_DOMAIN] = core_config
result[HOMEASSISTANT_DOMAIN] = core_config
# Merge packages
await merge_packages_config(
@ -168,8 +168,8 @@ async def async_check_ha_config_file( # noqa: C901
)
except vol.Invalid as err:
result.add_error(
format_schema_error(hass, err, HA_DOMAIN, core_config),
HA_DOMAIN,
format_schema_error(hass, err, HOMEASSISTANT_DOMAIN, core_config),
HOMEASSISTANT_DOMAIN,
core_config,
)
core_config = {}

View file

@ -4,7 +4,7 @@ from __future__ import annotations
import ast
from homeassistant.core import DOMAIN as HA_DOMAIN
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
from .model import Config, Integration
@ -12,7 +12,7 @@ CONFIG_SCHEMA_IGNORE = {
# Configuration under the homeassistant key is a special case, it's handled by
# conf_util.async_process_ha_core_config already during bootstrapping, not by
# a schema in the homeassistant integration.
HA_DOMAIN,
HOMEASSISTANT_DOMAIN,
}