Skip to content

Commit

Permalink
Merge branch 'edenhaus-optimize-hassfest-image' into edenhaus-test
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Aug 29, 2024
2 parents e115650 + eda6cf4 commit 0dacee7
Show file tree
Hide file tree
Showing 45 changed files with 399 additions and 499 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/august/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
type AugustConfigEntry = ConfigEntry[AugustData]


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_setup_entry(hass: HomeAssistant, entry: AugustConfigEntry) -> bool:
"""Set up August from a config entry."""
session = async_create_august_clientsession(hass)
august_gateway = AugustGateway(Path(hass.config.config_dir), session)
Expand Down
11 changes: 5 additions & 6 deletions homeassistant/components/august/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,11 @@ async def async_setup_entry(
for description in SENSOR_TYPES_DOORBELL
)

for doorbell in data.doorbells:
entities.extend(
AugustDoorbellBinarySensor(data, doorbell, description)
for description in SENSOR_TYPES_DOORBELL + SENSOR_TYPES_VIDEO_DOORBELL
)

entities.extend(
AugustDoorbellBinarySensor(data, doorbell, description)
for description in SENSOR_TYPES_DOORBELL + SENSOR_TYPES_VIDEO_DOORBELL
for doorbell in data.doorbells
)
async_add_entities(entities)


Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/august/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import AugustConfigEntry
from .entity import AugustEntityMixin
from .entity import AugustEntity


async def async_setup_entry(
Expand All @@ -18,7 +18,7 @@ async def async_setup_entry(
async_add_entities(AugustWakeLockButton(data, lock, "wake") for lock in data.locks)


class AugustWakeLockButton(AugustEntityMixin, ButtonEntity):
class AugustWakeLockButton(AugustEntity, ButtonEntity):
"""Representation of an August lock wake button."""

_attr_translation_key = "wake"
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/august/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from . import AugustConfigEntry, AugustData
from .const import DEFAULT_NAME, DEFAULT_TIMEOUT
from .entity import AugustEntityMixin
from .entity import AugustEntity

_LOGGER = logging.getLogger(__name__)

Expand All @@ -38,7 +38,7 @@ async def async_setup_entry(
)


class AugustCamera(AugustEntityMixin, Camera):
class AugustCamera(AugustEntity, Camera):
"""An implementation of an August security camera."""

_attr_translation_key = "camera"
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/august/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
DEVICE_TYPES = ["keypad", "lock", "camera", "doorbell", "door", "bell"]


class AugustEntityMixin(Entity):
class AugustEntity(Entity):
"""Base implementation for August device."""

_attr_should_poll = False
Expand Down Expand Up @@ -87,7 +87,7 @@ async def async_added_to_hass(self) -> None:
self._update_from_data()


class AugustDescriptionEntity(AugustEntityMixin):
class AugustDescriptionEntity(AugustEntity):
"""An August entity with a description."""

def __init__(
Expand Down
28 changes: 11 additions & 17 deletions homeassistant/components/august/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,24 @@ async def async_setup_entry(
) -> None:
"""Set up the august event platform."""
data = config_entry.runtime_data
entities: list[AugustEventEntity] = []

for lock in data.locks:
detail = data.get_device_detail(lock.device_id)
if detail.doorbell:
entities.extend(
AugustEventEntity(data, lock, description)
for description in TYPES_DOORBELL
)

for doorbell in data.doorbells:
entities.extend(
AugustEventEntity(data, doorbell, description)
for description in TYPES_DOORBELL + TYPES_VIDEO_DOORBELL
)

entities: list[AugustEventEntity] = [
AugustEventEntity(data, lock, description)
for description in TYPES_DOORBELL
for lock in data.locks
if (detail := data.get_device_detail(lock.device_id)) and detail.doorbell
]
entities.extend(
AugustEventEntity(data, doorbell, description)
for description in TYPES_DOORBELL + TYPES_VIDEO_DOORBELL
for doorbell in data.doorbells
)
async_add_entities(entities)


class AugustEventEntity(AugustDescriptionEntity, EventEntity):
"""An august event entity."""

entity_description: AugustEventEntityDescription
_attr_has_entity_name = True
_last_activity: Activity | None = None

@callback
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/august/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import homeassistant.util.dt as dt_util

from . import AugustConfigEntry, AugustData
from .entity import AugustEntityMixin
from .entity import AugustEntity

_LOGGER = logging.getLogger(__name__)

Expand All @@ -36,7 +36,7 @@ async def async_setup_entry(
async_add_entities(AugustLock(data, lock) for lock in data.locks)


class AugustLock(AugustEntityMixin, RestoreEntity, LockEntity):
class AugustLock(AugustEntity, RestoreEntity, LockEntity):
"""Representation of an August lock."""

_attr_name = None
Expand Down
21 changes: 11 additions & 10 deletions homeassistant/components/august/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from collections.abc import Callable
from dataclasses import dataclass
from typing import Any, Generic, TypeVar, cast
from typing import Any, cast

from yalexs.activity import ActivityType, LockOperationActivity
from yalexs.doorbell import Doorbell
Expand Down Expand Up @@ -42,7 +42,7 @@
OPERATION_METHOD_REMOTE,
OPERATION_METHOD_TAG,
)
from .entity import AugustDescriptionEntity, AugustEntityMixin
from .entity import AugustDescriptionEntity, AugustEntity


def _retrieve_device_battery_state(detail: LockDetail) -> int:
Expand All @@ -55,14 +55,13 @@ def _retrieve_linked_keypad_battery_state(detail: KeypadDetail) -> int | None:
return detail.battery_percentage


_T = TypeVar("_T", LockDetail, KeypadDetail)


@dataclass(frozen=True, kw_only=True)
class AugustSensorEntityDescription(SensorEntityDescription, Generic[_T]):
class AugustSensorEntityDescription[T: LockDetail | KeypadDetail](
SensorEntityDescription
):
"""Mixin for required keys."""

value_fn: Callable[[_T], int | None]
value_fn: Callable[[T], int | None]


SENSOR_TYPE_DEVICE_BATTERY = AugustSensorEntityDescription[LockDetail](
Expand Down Expand Up @@ -114,7 +113,7 @@ async def async_setup_entry(
async_add_entities(entities)


class AugustOperatorSensor(AugustEntityMixin, RestoreSensor):
class AugustOperatorSensor(AugustEntity, RestoreSensor):
"""Representation of an August lock operation sensor."""

_attr_translation_key = "operator"
Expand Down Expand Up @@ -198,10 +197,12 @@ async def async_added_to_hass(self) -> None:
self._operated_autorelock = last_attrs[ATTR_OPERATION_AUTORELOCK]


class AugustBatterySensor(AugustDescriptionEntity, SensorEntity, Generic[_T]):
class AugustBatterySensor[T: LockDetail | KeypadDetail](
AugustDescriptionEntity, SensorEntity
):
"""Representation of an August sensor."""

entity_description: AugustSensorEntityDescription[_T]
entity_description: AugustSensorEntityDescription[T]
_attr_device_class = SensorDeviceClass.BATTERY
_attr_native_unit_of_measurement = PERCENTAGE

Expand Down
7 changes: 1 addition & 6 deletions homeassistant/components/august/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,11 @@ def _activity_time_based(latest: Activity) -> Activity | None:
"""Get the latest state of the sensor."""
start = latest.activity_start_time
end = latest.activity_end_time + TIME_TO_DECLARE_DETECTION
if start <= _native_datetime() <= end:
if start <= datetime.now() <= end:
return latest
return None


def _native_datetime() -> datetime:
"""Return time in the format august uses without timezone."""
return datetime.now()


def retrieve_online_state(
data: AugustData, detail: DoorbellDetail | LockDetail
) -> bool:
Expand Down
12 changes: 6 additions & 6 deletions homeassistant/components/automation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,15 +991,15 @@ async def _create_automation_entities(

# Add trigger variables to variables
variables = None
if CONF_TRIGGER_VARIABLES in config_block:
if CONF_TRIGGER_VARIABLES in config_block and CONF_VARIABLES in config_block:
variables = ScriptVariables(
dict(config_block[CONF_TRIGGER_VARIABLES].as_dict())
)
if CONF_VARIABLES in config_block:
if variables:
variables.variables.update(config_block[CONF_VARIABLES].as_dict())
else:
variables = config_block[CONF_VARIABLES]
variables.variables.update(config_block[CONF_VARIABLES].as_dict())
elif CONF_TRIGGER_VARIABLES in config_block:
variables = config_block[CONF_TRIGGER_VARIABLES]
elif CONF_VARIABLES in config_block:
variables = config_block[CONF_VARIABLES]

entity = AutomationEntity(
automation_id,
Expand Down
28 changes: 16 additions & 12 deletions homeassistant/components/broadlink/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from functools import partial
import logging
import socket
from typing import TYPE_CHECKING, Any
from typing import Any

import broadlink as blk
from broadlink.exceptions import (
Expand Down Expand Up @@ -37,9 +37,7 @@ class BroadlinkFlowHandler(ConfigFlow, domain=DOMAIN):

VERSION = 1

def __init__(self) -> None:
"""Initialize the Broadlink flow."""
self.device: blk.Device | None = None
device: blk.Device

async def async_set_device(
self, device: blk.Device, raise_on_progress: bool = True
Expand Down Expand Up @@ -131,8 +129,6 @@ async def async_step_user(
)
return await self.async_step_auth()

if TYPE_CHECKING:
assert self.device
if device.mac == self.device.mac:
await self.async_set_device(device, raise_on_progress=False)
return await self.async_step_auth()
Expand All @@ -158,10 +154,10 @@ async def async_step_user(
errors=errors,
)

async def async_step_auth(self):
async def async_step_auth(self) -> ConfigFlowResult:
"""Authenticate to the device."""
device = self.device
errors = {}
errors: dict[str, str] = {}

try:
await self.hass.async_add_executor_job(device.auth)
Expand Down Expand Up @@ -211,7 +207,11 @@ async def async_step_auth(self):
)
return self.async_show_form(step_id="auth", errors=errors)

async def async_step_reset(self, user_input=None, errors=None):
async def async_step_reset(
self,
user_input: dict[str, Any] | None = None,
errors: dict[str, str] | None = None,
) -> ConfigFlowResult:
"""Guide the user to unlock the device manually.
We are unable to authenticate because the device is locked.
Expand All @@ -234,7 +234,9 @@ async def async_step_reset(self, user_input=None, errors=None):
{CONF_HOST: device.host[0], CONF_TIMEOUT: device.timeout}
)

async def async_step_unlock(self, user_input=None):
async def async_step_unlock(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Unlock the device.
The authentication succeeded, but the device is locked.
Expand Down Expand Up @@ -288,10 +290,12 @@ async def async_step_unlock(self, user_input=None):
},
)

async def async_step_finish(self, user_input=None):
async def async_step_finish(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Choose a name for the device and create config entry."""
device = self.device
errors = {}
errors: dict[str, str] = {}

# Abort reauthentication flow.
self._abort_if_unique_id_configured(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/camera/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/camera",
"integration_type": "entity",
"quality_scale": "internal",
"requirements": ["PyTurboJPEG==1.7.1"]
"requirements": ["PyTurboJPEG==1.7.5"]
}
14 changes: 10 additions & 4 deletions homeassistant/components/control4/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import logging
from typing import Any
from typing import TYPE_CHECKING, Any

from aiohttp.client_exceptions import ClientError
from pyControl4.account import C4Account
Expand All @@ -23,7 +23,7 @@
CONF_SCAN_INTERVAL,
CONF_USERNAME,
)
from homeassistant.core import callback
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import HomeAssistantError
from homeassistant.helpers import aiohttp_client, config_validation as cv
from homeassistant.helpers.device_registry import format_mac
Expand All @@ -49,7 +49,9 @@
class Control4Validator:
"""Validates that config details can be used to authenticate and communicate with Control4."""

def __init__(self, host, username, password, hass):
def __init__(
self, host: str, username: str, password: str, hass: HomeAssistant
) -> None:
"""Initialize."""
self.host = host
self.username = username
Expand Down Expand Up @@ -126,6 +128,8 @@ async def async_step_user(

if not errors:
controller_unique_id = hub.controller_unique_id
if TYPE_CHECKING:
assert hub.controller_unique_id
mac = (controller_unique_id.split("_", 3))[2]
formatted_mac = format_mac(mac)
await self.async_set_unique_id(formatted_mac)
Expand Down Expand Up @@ -160,7 +164,9 @@ def __init__(self, config_entry: ConfigEntry) -> None:
"""Initialize options flow."""
self.config_entry = config_entry

async def async_step_init(self, user_input=None):
async def async_step_init(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle options flow."""
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
Expand Down
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.4", "home-assistant-intents==2024.8.7"]
"requirements": ["hassil==1.7.4", "home-assistant-intents==2024.8.29"]
}
2 changes: 1 addition & 1 deletion homeassistant/components/daikin/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/daikin",
"iot_class": "local_polling",
"loggers": ["pydaikin"],
"requirements": ["pydaikin==2.13.5"],
"requirements": ["pydaikin==2.13.6"],
"zeroconf": ["_dkapi._tcp.local."]
}
Loading

0 comments on commit 0dacee7

Please sign in to comment.