From ca3d13b5cc8876ac7fc352f39d809e3b894b0329 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Tue, 29 Oct 2024 17:26:08 +0100 Subject: [PATCH] Sort some code in core_config (#129388) --- homeassistant/core_config.py | 120 +++++++++++++++++------------------ 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/homeassistant/core_config.py b/homeassistant/core_config.py index 2b539263456..25f745f110c 100644 --- a/homeassistant/core_config.py +++ b/homeassistant/core_config.py @@ -354,33 +354,33 @@ async def async_process_ha_core_config(hass: HomeAssistant, config: dict) -> Non if any( k in config for k in ( + CONF_COUNTRY, + CONF_CURRENCY, + CONF_ELEVATION, + CONF_EXTERNAL_URL, + CONF_INTERNAL_URL, + CONF_LANGUAGE, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, - CONF_ELEVATION, + CONF_RADIUS, CONF_TIME_ZONE, CONF_UNIT_SYSTEM, - CONF_EXTERNAL_URL, - CONF_INTERNAL_URL, - CONF_CURRENCY, - CONF_COUNTRY, - CONF_LANGUAGE, - CONF_RADIUS, ) ): hac.config_source = ConfigSource.YAML for key, attr in ( + (CONF_COUNTRY, "country"), + (CONF_CURRENCY, "currency"), + (CONF_ELEVATION, "elevation"), + (CONF_EXTERNAL_URL, "external_url"), + (CONF_INTERNAL_URL, "internal_url"), + (CONF_LANGUAGE, "language"), (CONF_LATITUDE, "latitude"), (CONF_LONGITUDE, "longitude"), - (CONF_NAME, "location_name"), - (CONF_ELEVATION, "elevation"), - (CONF_INTERNAL_URL, "internal_url"), - (CONF_EXTERNAL_URL, "external_url"), (CONF_MEDIA_DIRS, "media_dirs"), - (CONF_CURRENCY, "currency"), - (CONF_COUNTRY, "country"), - (CONF_LANGUAGE, "language"), + (CONF_NAME, "location_name"), (CONF_RADIUS, "radius"), ): if key in config: @@ -647,36 +647,36 @@ class Config: return False def as_dict(self) -> dict[str, Any]: - """Create a dictionary representation of the configuration. + """Return a dictionary representation of the configuration. Async friendly. """ allowlist_external_dirs = list(self.allowlist_external_dirs) return { - "latitude": self.latitude, - "longitude": self.longitude, - "elevation": self.elevation, - "unit_system": self.units.as_dict(), - "location_name": self.location_name, - "time_zone": self.time_zone, - "components": list(self.components), - "config_dir": self.config_dir, - # legacy, backwards compat - "whitelist_external_dirs": allowlist_external_dirs, "allowlist_external_dirs": allowlist_external_dirs, "allowlist_external_urls": list(self.allowlist_external_urls), - "version": __version__, + "components": list(self.components), + "config_dir": self.config_dir, "config_source": self.config_source, - "recovery_mode": self.recovery_mode, - "state": self.hass.state.value, + "country": self.country, + "currency": self.currency, + "debug": self.debug, + "elevation": self.elevation, "external_url": self.external_url, "internal_url": self.internal_url, - "currency": self.currency, - "country": self.country, "language": self.language, - "safe_mode": self.safe_mode, - "debug": self.debug, + "latitude": self.latitude, + "location_name": self.location_name, + "longitude": self.longitude, "radius": self.radius, + "recovery_mode": self.recovery_mode, + "safe_mode": self.safe_mode, + "state": self.hass.state.value, + "time_zone": self.time_zone, + "unit_system": self.units.as_dict(), + "version": __version__, + # legacy, backwards compat + "whitelist_external_dirs": allowlist_external_dirs, } async def async_set_time_zone(self, time_zone_str: str) -> None: @@ -710,49 +710,49 @@ class Config: async def _async_update( self, *, - source: ConfigSource, - latitude: float | None = None, - longitude: float | None = None, + country: str | UndefinedType | None = UNDEFINED, + currency: str | None = None, elevation: int | None = None, - unit_system: str | None = None, - location_name: str | None = None, - time_zone: str | None = None, external_url: str | UndefinedType | None = UNDEFINED, internal_url: str | UndefinedType | None = UNDEFINED, - currency: str | None = None, - country: str | UndefinedType | None = UNDEFINED, language: str | None = None, + latitude: float | None = None, + location_name: str | None = None, + longitude: float | None = None, radius: int | None = None, + source: ConfigSource, + time_zone: str | None = None, + unit_system: str | None = None, ) -> None: """Update the configuration from a dictionary.""" self.config_source = source - if latitude is not None: - self.latitude = latitude - if longitude is not None: - self.longitude = longitude + if country is not UNDEFINED: + self.country = country + if currency is not None: + self.currency = currency if elevation is not None: self.elevation = elevation + if external_url is not UNDEFINED: + self.external_url = external_url + if internal_url is not UNDEFINED: + self.internal_url = internal_url + if language is not None: + self.language = language + if latitude is not None: + self.latitude = latitude + if location_name is not None: + self.location_name = location_name + if longitude is not None: + self.longitude = longitude + if radius is not None: + self.radius = radius + if time_zone is not None: + await self.async_set_time_zone(time_zone) if unit_system is not None: try: self.units = get_unit_system(unit_system) except ValueError: self.units = METRIC_SYSTEM - if location_name is not None: - self.location_name = location_name - if time_zone is not None: - await self.async_set_time_zone(time_zone) - if external_url is not UNDEFINED: - self.external_url = external_url - if internal_url is not UNDEFINED: - self.internal_url = internal_url - if currency is not None: - self.currency = currency - if country is not UNDEFINED: - self.country = country - if language is not None: - self.language = language - if radius is not None: - self.radius = radius async def async_update(self, **kwargs: Any) -> None: """Update the configuration from a dictionary."""