Skip to content

Commit

Permalink
Merge branch 'dev' into tplink/quality_scale
Browse files Browse the repository at this point in the history
  • Loading branch information
sdb9696 authored Jan 7, 2025
2 parents b8f5669 + 1496da8 commit 16a6248
Show file tree
Hide file tree
Showing 52 changed files with 523 additions and 235 deletions.
1 change: 0 additions & 1 deletion homeassistant/components/dsmr/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ def rename_old_gas_to_mbus(
ent_reg.async_update_entity(
entity.entity_id,
new_unique_id=mbus_device_id,
device_id=mbus_device_id,
)
except ValueError:
LOGGER.debug(
Expand Down
14 changes: 6 additions & 8 deletions homeassistant/components/heos/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rules:
docs-actions: done
docs-high-level-description: done
docs-installation-instructions: done
docs-removal-instructions: todo
docs-removal-instructions: done
entity-event-setup: done
entity-unique-id: done
has-entity-name: done
Expand Down Expand Up @@ -60,14 +60,12 @@ rules:
status: todo
comment: Explore if this is possible.
discovery: done
docs-data-update: todo
docs-examples: todo
docs-known-limitations: todo
docs-supported-devices: todo
docs-data-update: done
docs-examples: done
docs-known-limitations: done
docs-supported-devices: done
docs-supported-functions: done
docs-troubleshooting:
status: todo
comment: Has some troublehsooting setps, but needs to be improved
docs-troubleshooting: done
docs-use-cases: done
dynamic-devices: todo
entity-category: done
Expand Down
4 changes: 1 addition & 3 deletions homeassistant/components/onewire/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

from pyownet import protocol

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr

from .const import DOMAIN, PLATFORMS
from .onewirehub import CannotConnect, OneWireHub
from .onewirehub import CannotConnect, OneWireConfigEntry, OneWireHub

_LOGGER = logging.getLogger(__name__)
type OneWireConfigEntry = ConfigEntry[OneWireHub]


async def async_setup_entry(hass: HomeAssistant, entry: OneWireConfigEntry) -> bool:
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/onewire/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass
from datetime import timedelta
import os

from homeassistant.components.binary_sensor import (
Expand All @@ -14,10 +15,12 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import OneWireConfigEntry
from .const import DEVICE_KEYS_0_3, DEVICE_KEYS_0_7, DEVICE_KEYS_A_B, READ_MODE_BOOL
from .entity import OneWireEntity, OneWireEntityDescription
from .onewirehub import OneWireHub
from .onewirehub import OneWireConfigEntry, OneWireHub

PARALLEL_UPDATES = 1
SCAN_INTERVAL = timedelta(seconds=30)


@dataclass(frozen=True)
Expand Down
88 changes: 44 additions & 44 deletions homeassistant/components/onewire/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

import voluptuous as vol

from homeassistant.config_entries import (
ConfigEntry,
ConfigFlow,
ConfigFlowResult,
OptionsFlow,
)
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow
from homeassistant.const import CONF_HOST, CONF_PORT
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import config_validation as cv, device_registry as dr
Expand All @@ -29,7 +24,7 @@
OPTION_ENTRY_SENSOR_PRECISION,
PRECISION_MAPPING_FAMILY_28,
)
from .onewirehub import CannotConnect, OneWireHub
from .onewirehub import CannotConnect, OneWireConfigEntry, OneWireHub

DATA_SCHEMA = vol.Schema(
{
Expand All @@ -39,70 +34,75 @@
)


async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, str]:
"""Validate the user input allows us to connect.
Data has the keys from DATA_SCHEMA with values provided by the user.
"""
async def validate_input(
hass: HomeAssistant, data: dict[str, Any], errors: dict[str, str]
) -> None:
"""Validate the user input allows us to connect."""

hub = OneWireHub(hass)

host = data[CONF_HOST]
port = data[CONF_PORT]
# Raises CannotConnect exception on failure
await hub.connect(host, port)

# Return info that you want to store in the config entry.
return {"title": host}
try:
await hub.connect(data[CONF_HOST], data[CONF_PORT])
except CannotConnect:
errors["base"] = "cannot_connect"


class OneWireFlowHandler(ConfigFlow, domain=DOMAIN):
"""Handle 1-Wire config flow."""

VERSION = 1

def __init__(self) -> None:
"""Initialize 1-Wire config flow."""
self.onewire_config: dict[str, Any] = {}

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle 1-Wire config flow start.
Let user manually input configuration.
"""
"""Handle 1-Wire config flow start."""
errors: dict[str, str] = {}
if user_input:
# Prevent duplicate entries
self._async_abort_entries_match(
{
CONF_HOST: user_input[CONF_HOST],
CONF_PORT: user_input[CONF_PORT],
}
{CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]}
)

self.onewire_config.update(user_input)

try:
info = await validate_input(self.hass, user_input)
except CannotConnect:
errors["base"] = "cannot_connect"
else:
await validate_input(self.hass, user_input, errors)
if not errors:
return self.async_create_entry(
title=info["title"], data=self.onewire_config
title=user_input[CONF_HOST], data=user_input
)

return self.async_show_form(
step_id="user",
data_schema=DATA_SCHEMA,
data_schema=self.add_suggested_values_to_schema(DATA_SCHEMA, user_input),
errors=errors,
)

async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle 1-Wire reconfiguration."""
errors: dict[str, str] = {}
reconfigure_entry = self._get_reconfigure_entry()
if user_input:
self._async_abort_entries_match(
{CONF_HOST: user_input[CONF_HOST], CONF_PORT: user_input[CONF_PORT]}
)

await validate_input(self.hass, user_input, errors)
if not errors:
return self.async_update_reload_and_abort(
reconfigure_entry, data_updates=user_input
)

return self.async_show_form(
step_id="reconfigure",
data_schema=self.add_suggested_values_to_schema(
DATA_SCHEMA, reconfigure_entry.data | (user_input or {})
),
description_placeholders={"name": reconfigure_entry.title},
errors=errors,
)

@staticmethod
@callback
def async_get_options_flow(
config_entry: ConfigEntry,
config_entry: OneWireConfigEntry,
) -> OnewireOptionsFlowHandler:
"""Get the options flow for this handler."""
return OnewireOptionsFlowHandler(config_entry)
Expand All @@ -126,7 +126,7 @@ class OnewireOptionsFlowHandler(OptionsFlow):
current_device: str
"""Friendly name of the currently selected device."""

def __init__(self, config_entry: ConfigEntry) -> None:
def __init__(self, config_entry: OneWireConfigEntry) -> None:
"""Initialize options flow."""
self.options = deepcopy(dict(config_entry.options))

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/onewire/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.const import CONF_HOST
from homeassistant.core import HomeAssistant

from . import OneWireConfigEntry
from .onewirehub import OneWireConfigEntry

TO_REDACT = {CONF_HOST}

Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/onewire/onewirehub.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

_LOGGER = logging.getLogger(__name__)

type OneWireConfigEntry = ConfigEntry[OneWireHub]


def _is_known_device(device_family: str, device_type: str | None) -> bool:
"""Check if device family/type is known to the library."""
Expand All @@ -70,7 +72,7 @@ async def connect(self, host: str, port: int) -> None:
except protocol.ConnError as exc:
raise CannotConnect from exc

async def initialize(self, config_entry: ConfigEntry) -> None:
async def initialize(self, config_entry: OneWireConfigEntry) -> None:
"""Initialize a config entry."""
host = config_entry.data[CONF_HOST]
port = config_entry.data[CONF_PORT]
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/onewire/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from collections.abc import Callable, Mapping
import dataclasses
from datetime import timedelta
import logging
import os
from types import MappingProxyType
Expand All @@ -28,7 +29,6 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType

from . import OneWireConfigEntry
from .const import (
DEVICE_KEYS_0_3,
DEVICE_KEYS_A_B,
Expand All @@ -39,7 +39,10 @@
READ_MODE_INT,
)
from .entity import OneWireEntity, OneWireEntityDescription
from .onewirehub import OneWireHub
from .onewirehub import OneWireConfigEntry, OneWireHub

PARALLEL_UPDATES = 1
SCAN_INTERVAL = timedelta(seconds=30)


@dataclasses.dataclass(frozen=True)
Expand Down
19 changes: 16 additions & 3 deletions homeassistant/components/onewire/strings.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
{
"config": {
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
},
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]"
},
"step": {
"reconfigure": {
"data": {
"host": "[%key:common::config_flow::data::host%]",
"port": "[%key:common::config_flow::data::port%]"
},
"data_description": {
"host": "[%key:component::onewire::config::step::user::data_description::host%]",
"port": "[%key:component::onewire::config::step::user::data_description::port%]"
},
"description": "Update OWServer configuration for {name}"
},
"user": {
"data": {
"host": "[%key:common::config_flow::data::host%]",
"port": "[%key:common::config_flow::data::port%]"
},
"data_description": {
"host": "The hostname or IP address of your 1-Wire device."
"host": "The hostname or IP address of your OWServer instance.",
"port": "The port of your OWServer instance (default is 4304)."
},
"title": "Set server details"
"title": "Set OWServer instance details"
}
}
},
Expand Down
7 changes: 5 additions & 2 deletions homeassistant/components/onewire/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

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

Expand All @@ -11,10 +12,12 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from . import OneWireConfigEntry
from .const import DEVICE_KEYS_0_3, DEVICE_KEYS_0_7, DEVICE_KEYS_A_B, READ_MODE_BOOL
from .entity import OneWireEntity, OneWireEntityDescription
from .onewirehub import OneWireHub
from .onewirehub import OneWireConfigEntry, OneWireHub

PARALLEL_UPDATES = 1
SCAN_INTERVAL = timedelta(seconds=30)


@dataclass(frozen=True)
Expand Down
15 changes: 10 additions & 5 deletions homeassistant/components/overkiz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
PLATFORMS,
UPDATE_INTERVAL,
UPDATE_INTERVAL_ALL_ASSUMED_STATE,
UPDATE_INTERVAL_LOCAL,
)
from .coordinator import OverkizDataUpdateCoordinator

Expand Down Expand Up @@ -116,13 +117,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: OverkizDataConfigEntry)

if coordinator.is_stateless:
LOGGER.debug(
(
"All devices have an assumed state. Update interval has been reduced"
" to: %s"
),
"All devices have an assumed state. Update interval has been reduced to: %s",
UPDATE_INTERVAL_ALL_ASSUMED_STATE,
)
coordinator.update_interval = UPDATE_INTERVAL_ALL_ASSUMED_STATE
coordinator.set_update_interval(UPDATE_INTERVAL_ALL_ASSUMED_STATE)

if api_type == APIType.LOCAL:
LOGGER.debug(
"Devices connect via Local API. Update interval has been reduced to: %s",
UPDATE_INTERVAL_LOCAL,
)
coordinator.set_update_interval(UPDATE_INTERVAL_LOCAL)

platforms: defaultdict[Platform, list[Device]] = defaultdict(list)

Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/overkiz/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
DEFAULT_HOST: Final = "gateway-xxxx-xxxx-xxxx.local:8443"

UPDATE_INTERVAL: Final = timedelta(seconds=30)
UPDATE_INTERVAL_LOCAL: Final = timedelta(seconds=5)
UPDATE_INTERVAL_ALL_ASSUMED_STATE: Final = timedelta(minutes=60)

PLATFORMS: list[Platform] = [
Expand Down
Loading

0 comments on commit 16a6248

Please sign in to comment.