Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
frenck committed Jun 21, 2024
2 parents 394dafd + febcb33 commit b315b56
Show file tree
Hide file tree
Showing 39 changed files with 278 additions and 112 deletions.
61 changes: 39 additions & 22 deletions homeassistant/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,39 @@ async def async_setup_hass(
runtime_config: RuntimeConfig,
) -> core.HomeAssistant | None:
"""Set up Home Assistant."""
hass = core.HomeAssistant(runtime_config.config_dir)

async_enable_logging(
hass,
runtime_config.verbose,
runtime_config.log_rotate_days,
runtime_config.log_file,
runtime_config.log_no_color,
)

if runtime_config.debug or hass.loop.get_debug():
hass.config.debug = True
def create_hass() -> core.HomeAssistant:
"""Create the hass object and do basic setup."""
hass = core.HomeAssistant(runtime_config.config_dir)
loader.async_setup(hass)

async_enable_logging(
hass,
runtime_config.verbose,
runtime_config.log_rotate_days,
runtime_config.log_file,
runtime_config.log_no_color,
)

if runtime_config.debug or hass.loop.get_debug():
hass.config.debug = True

hass.config.safe_mode = runtime_config.safe_mode
hass.config.skip_pip = runtime_config.skip_pip
hass.config.skip_pip_packages = runtime_config.skip_pip_packages

return hass

async def stop_hass(hass: core.HomeAssistant) -> None:
"""Stop hass."""
# Ask integrations to shut down. It's messy but we can't
# do a clean stop without knowing what is broken
with contextlib.suppress(TimeoutError):
async with hass.timeout.async_timeout(10):
await hass.async_stop()

hass = create_hass()

hass.config.safe_mode = runtime_config.safe_mode
hass.config.skip_pip = runtime_config.skip_pip
hass.config.skip_pip_packages = runtime_config.skip_pip_packages
if runtime_config.skip_pip or runtime_config.skip_pip_packages:
_LOGGER.warning(
"Skipping pip installation of required modules. This may cause issues"
Expand All @@ -283,7 +300,6 @@ async def async_setup_hass(

_LOGGER.info("Config directory: %s", runtime_config.config_dir)

loader.async_setup(hass)
block_async_io.enable()

config_dict = None
Expand All @@ -309,27 +325,28 @@ async def async_setup_hass(

if config_dict is None:
recovery_mode = True
await stop_hass(hass)
hass = create_hass()

elif not basic_setup_success:
_LOGGER.warning("Unable to set up core integrations. Activating recovery mode")
recovery_mode = True
await stop_hass(hass)
hass = create_hass()

elif any(domain not in hass.config.components for domain in CRITICAL_INTEGRATIONS):
_LOGGER.warning(
"Detected that %s did not load. Activating recovery mode",
",".join(CRITICAL_INTEGRATIONS),
)
# Ask integrations to shut down. It's messy but we can't
# do a clean stop without knowing what is broken
with contextlib.suppress(TimeoutError):
async with hass.timeout.async_timeout(10):
await hass.async_stop()

recovery_mode = True
old_config = hass.config
old_logging = hass.data.get(DATA_LOGGING)

hass = core.HomeAssistant(old_config.config_dir)
recovery_mode = True
await stop_hass(hass)
hass = create_hass()

if old_logging:
hass.data[DATA_LOGGING] = old_logging
hass.config.debug = old_config.debug
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/aemet/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/aemet",
"iot_class": "cloud_polling",
"loggers": ["aemet_opendata"],
"requirements": ["AEMET-OpenData==0.5.1"]
"requirements": ["AEMET-OpenData==0.5.2"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/canary/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/canary",
"iot_class": "cloud_polling",
"loggers": ["canary"],
"requirements": ["py-canary==0.5.3"]
"requirements": ["py-canary==0.5.4"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/conversation/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/conversation",
"integration_type": "system",
"quality_scale": "internal",
"requirements": ["hassil==1.7.1", "home-assistant-intents==2024.6.5"]
"requirements": ["hassil==1.7.1", "home-assistant-intents==2024.6.21"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/ecobee/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class EcobeeWeather(WeatherEntity):
_attr_native_pressure_unit = UnitOfPressure.HPA
_attr_native_temperature_unit = UnitOfTemperature.FAHRENHEIT
_attr_native_visibility_unit = UnitOfLength.METERS
_attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
_attr_native_wind_speed_unit = UnitOfSpeed.MILES_PER_HOUR
_attr_has_entity_name = True
_attr_name = None
_attr_supported_features = WeatherEntityFeature.FORECAST_DAILY
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/environment_canada/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/environment_canada",
"iot_class": "cloud_polling",
"loggers": ["env_canada"],
"requirements": ["env-canada==0.6.2"]
"requirements": ["env-canada==0.6.3"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/holiday/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/holiday",
"iot_class": "local_polling",
"requirements": ["holidays==0.50", "babel==2.13.1"]
"requirements": ["holidays==0.51", "babel==2.15.0"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/hydrawise/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/hydrawise",
"iot_class": "cloud_polling",
"loggers": ["pydrawise"],
"requirements": ["pydrawise==2024.6.3"]
"requirements": ["pydrawise==2024.6.4"]
}
17 changes: 12 additions & 5 deletions homeassistant/components/hydrawise/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _get_zone_daily_active_water_use(sensor: HydrawiseSensor) -> float:
return float(daily_water_summary.active_use_by_zone_id.get(sensor.zone.id, 0.0))


def _get_controller_daily_active_water_use(sensor: HydrawiseSensor) -> float:
def _get_controller_daily_active_water_use(sensor: HydrawiseSensor) -> float | None:
"""Get active water use for the controller."""
daily_water_summary = sensor.coordinator.data.daily_water_use[sensor.controller.id]
return daily_water_summary.total_active_use
Expand All @@ -71,23 +71,20 @@ def _get_controller_daily_total_water_use(sensor: HydrawiseSensor) -> float | No
key="daily_total_water_use",
translation_key="daily_total_water_use",
device_class=SensorDeviceClass.VOLUME,
native_unit_of_measurement=UnitOfVolume.GALLONS,
suggested_display_precision=1,
value_fn=_get_controller_daily_total_water_use,
),
HydrawiseSensorEntityDescription(
key="daily_active_water_use",
translation_key="daily_active_water_use",
device_class=SensorDeviceClass.VOLUME,
native_unit_of_measurement=UnitOfVolume.GALLONS,
suggested_display_precision=1,
value_fn=_get_controller_daily_active_water_use,
),
HydrawiseSensorEntityDescription(
key="daily_inactive_water_use",
translation_key="daily_inactive_water_use",
device_class=SensorDeviceClass.VOLUME,
native_unit_of_measurement=UnitOfVolume.GALLONS,
suggested_display_precision=1,
value_fn=_get_controller_daily_inactive_water_use,
),
Expand All @@ -98,7 +95,6 @@ def _get_controller_daily_total_water_use(sensor: HydrawiseSensor) -> float | No
key="daily_active_water_use",
translation_key="daily_active_water_use",
device_class=SensorDeviceClass.VOLUME,
native_unit_of_measurement=UnitOfVolume.GALLONS,
suggested_display_precision=1,
value_fn=_get_zone_daily_active_water_use,
),
Expand Down Expand Up @@ -165,6 +161,17 @@ class HydrawiseSensor(HydrawiseEntity, SensorEntity):

entity_description: HydrawiseSensorEntityDescription

@property
def native_unit_of_measurement(self) -> str | None:
"""Return the unit_of_measurement of the sensor."""
if self.entity_description.device_class != SensorDeviceClass.VOLUME:
return self.entity_description.native_unit_of_measurement
return (
UnitOfVolume.GALLONS
if self.coordinator.data.user.units.units_name == "imperial"
else UnitOfVolume.LITERS
)

@property
def icon(self) -> str | None:
"""Icon of the entity based on the value."""
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/imap/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"documentation": "https://www.home-assistant.io/integrations/imap",
"iot_class": "cloud_push",
"loggers": ["aioimaplib"],
"requirements": ["aioimaplib==1.0.1"]
"requirements": ["aioimaplib==1.1.0"]
}
5 changes: 4 additions & 1 deletion homeassistant/components/jewish_calendar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ def get_unique_prefix(
havdalah_offset: int | None,
) -> str:
"""Create a prefix for unique ids."""
# location.altitude was unset before 2024.6 when this method
# was used to create the unique id. As such it would always
# use the default altitude of 754.
config_properties = [
location.latitude,
location.longitude,
location.timezone,
location.altitude,
754,
location.diaspora,
language,
candle_lighting_offset,
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/jewish_calendar/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"documentation": "https://www.home-assistant.io/integrations/jewish_calendar",
"iot_class": "calculated",
"loggers": ["hdate"],
"requirements": ["hdate==0.10.8"],
"requirements": ["hdate==0.10.9"],
"single_config_entry": true
}
1 change: 1 addition & 0 deletions homeassistant/components/matter/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
(5010, 769, "3.0", "1.0.0"),
(4999, 25057, "1.0", "27.0"),
(4448, 36866, "V1", "V1.0.0.5"),
(5009, 514, "1.0", "1.0.0"),
)


Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/onkyo/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def update(self) -> None:
del self._attr_extra_state_attributes[ATTR_PRESET]

self._attr_is_volume_muted = bool(mute_raw[1] == "on")
# AMP_VOL/MAX_RECEIVER_VOL*(MAX_VOL/100)
# AMP_VOL / (MAX_RECEIVER_VOL * (MAX_VOL / 100))
self._attr_volume_level = volume_raw[1] / (
self._receiver_max_volume * self._max_volume / 100
)
Expand Down Expand Up @@ -511,9 +511,9 @@ def update(self) -> None:
elif ATTR_PRESET in self._attr_extra_state_attributes:
del self._attr_extra_state_attributes[ATTR_PRESET]
if self._supports_volume:
# AMP_VOL/MAX_RECEIVER_VOL*(MAX_VOL/100)
self._attr_volume_level = (
volume_raw[1] / self._receiver_max_volume * (self._max_volume / 100)
# AMP_VOL / (MAX_RECEIVER_VOL * (MAX_VOL / 100))
self._attr_volume_level = volume_raw[1] / (
self._receiver_max_volume * self._max_volume / 100
)

@property
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/plugwise/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"integration_type": "hub",
"iot_class": "local_polling",
"loggers": ["plugwise"],
"requirements": ["plugwise==0.37.3"],
"requirements": ["plugwise==0.37.4.1"],
"zeroconf": ["_plugwise._tcp.local."]
}
7 changes: 6 additions & 1 deletion homeassistant/components/songpal/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ async def async_will_remove_from_hass(self) -> None:

async def _get_sound_modes_info(self):
"""Get available sound modes and the active one."""
settings = await self._dev.get_sound_settings("soundField")
for settings in await self._dev.get_sound_settings():
if settings.target == "soundField":
break
else:
return None, {}

if isinstance(settings, Setting):
settings = [settings]

Expand Down
12 changes: 1 addition & 11 deletions homeassistant/components/spotify/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
from typing import Any

Expand All @@ -22,6 +21,7 @@

from .browse_media import async_browse_media
from .const import DOMAIN, LOGGER, SPOTIFY_SCOPES
from .models import HomeAssistantSpotifyData
from .util import (
is_spotify_media_type,
resolve_spotify_media_type,
Expand All @@ -39,16 +39,6 @@
]


@dataclass
class HomeAssistantSpotifyData:
"""Spotify data stored in the Home Assistant data object."""

client: Spotify
current_user: dict[str, Any]
devices: DataUpdateCoordinator[list[dict[str, Any]]]
session: OAuth2Session


type SpotifyConfigEntry = ConfigEntry[HomeAssistantSpotifyData]


Expand Down
6 changes: 2 additions & 4 deletions homeassistant/components/spotify/browse_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from enum import StrEnum
from functools import partial
import logging
from typing import TYPE_CHECKING, Any
from typing import Any

from spotipy import Spotify
import yarl
Expand All @@ -20,11 +20,9 @@
from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session

from .const import DOMAIN, MEDIA_PLAYER_PREFIX, MEDIA_TYPE_SHOW, PLAYABLE_MEDIA_TYPES
from .models import HomeAssistantSpotifyData
from .util import fetch_image_url

if TYPE_CHECKING:
from . import HomeAssistantSpotifyData

BROWSE_LIMIT = 48


Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/spotify/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.dt import utcnow

from . import HomeAssistantSpotifyData, SpotifyConfigEntry
from . import SpotifyConfigEntry
from .browse_media import async_browse_media_internal
from .const import DOMAIN, MEDIA_PLAYER_PREFIX, PLAYABLE_MEDIA_TYPES, SPOTIFY_SCOPES
from .models import HomeAssistantSpotifyData
from .util import fetch_image_url

_LOGGER = logging.getLogger(__name__)
Expand Down
19 changes: 19 additions & 0 deletions homeassistant/components/spotify/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Models for use in Spotify integration."""

from dataclasses import dataclass
from typing import Any

from spotipy import Spotify

from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator


@dataclass
class HomeAssistantSpotifyData:
"""Spotify data stored in the Home Assistant data object."""

client: Spotify
current_user: dict[str, Any]
devices: DataUpdateCoordinator[list[dict[str, Any]]]
session: OAuth2Session
2 changes: 2 additions & 0 deletions homeassistant/components/synology_dsm/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

ENTITY_UNIT_LOAD = "load"

SHARED_SUFFIX = "_shared"

# Signals
SIGNAL_CAMERA_SOURCE_CHANGED = "synology_dsm.camera_stream_source_changed"

Expand Down
Loading

0 comments on commit b315b56

Please sign in to comment.