mirror of
https://github.com/home-assistant/core.git
synced 2025-11-16 14:30:22 +00:00
Compare commits
66 Commits
claude/tri
...
tibber_dat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21554af6a1 | ||
|
|
b4aae93c45 | ||
|
|
1f9c244c5c | ||
|
|
9fa1b1b8df | ||
|
|
f3ac3ecf05 | ||
|
|
9477b2206b | ||
|
|
bfa1116115 | ||
|
|
4984237987 | ||
|
|
3839573151 | ||
|
|
e02dc53df3 | ||
|
|
bedae1e12c | ||
|
|
b4eb73be98 | ||
|
|
0ac3f776fa | ||
|
|
8e8a4fff11 | ||
|
|
579ffcc64d | ||
|
|
81943fb31d | ||
|
|
70dd0bf12e | ||
|
|
c2d462c1e7 | ||
|
|
49e050cc60 | ||
|
|
f6d829a2f3 | ||
|
|
e44e3b6f25 | ||
|
|
af603661c0 | ||
|
|
35c6113777 | ||
|
|
3c2f729ddc | ||
|
|
0d63cb765f | ||
|
|
3cb414511b | ||
|
|
f55c36d42d | ||
|
|
26bb301cc0 | ||
|
|
4159e483ee | ||
|
|
7eb6f7cc07 | ||
|
|
a7d01b0b03 | ||
|
|
1e5cfddf83 | ||
|
|
006fc5b10a | ||
|
|
35a4b685b3 | ||
|
|
b166818ef4 | ||
|
|
34cd9f11d0 | ||
|
|
0711d62085 | ||
|
|
f70aeafb5f | ||
|
|
e2279b3589 | ||
|
|
87b68e99ec | ||
|
|
b6c8b787e8 | ||
|
|
78f26edc29 | ||
|
|
5e6a72de90 | ||
|
|
dcc559f8b6 | ||
|
|
eda49cced0 | ||
|
|
14e41ab119 | ||
|
|
46151456d8 | ||
|
|
39773a022a | ||
|
|
5f49a6450f | ||
|
|
dc8425c580 | ||
|
|
910bd371e4 | ||
|
|
802a225e11 | ||
|
|
84f66fa689 | ||
|
|
0b7e88d0e0 | ||
|
|
1fcaf95df5 | ||
|
|
6c7434531f | ||
|
|
5ec1c2b68b | ||
|
|
d8636d8346 | ||
|
|
434763c74d | ||
|
|
8cd2c1b43b | ||
|
|
44711787a4 | ||
|
|
98fd0ee683 | ||
|
|
303e4ce961 | ||
|
|
76f29298cd | ||
|
|
17f5d0a69f | ||
|
|
90561de438 |
2
.github/workflows/ci.yaml
vendored
2
.github/workflows/ci.yaml
vendored
@@ -37,7 +37,7 @@ on:
|
|||||||
type: boolean
|
type: boolean
|
||||||
|
|
||||||
env:
|
env:
|
||||||
CACHE_VERSION: 1
|
CACHE_VERSION: 2
|
||||||
UV_CACHE_VERSION: 1
|
UV_CACHE_VERSION: 1
|
||||||
MYPY_CACHE_VERSION: 1
|
MYPY_CACHE_VERSION: 1
|
||||||
HA_SHORT_VERSION: "2025.12"
|
HA_SHORT_VERSION: "2025.12"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
},
|
},
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pyecobee"],
|
"loggers": ["pyecobee"],
|
||||||
"requirements": ["python-ecobee-api==0.2.20"],
|
"requirements": ["python-ecobee-api==0.3.2"],
|
||||||
"single_config_entry": true,
|
"single_config_entry": true,
|
||||||
"zeroconf": [
|
"zeroconf": [
|
||||||
{
|
{
|
||||||
|
|||||||
84
homeassistant/components/emoncms/quality_scale.yaml
Normal file
84
homeassistant/components/emoncms/quality_scale.yaml
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
rules:
|
||||||
|
# todo : add get_feed_list to the library
|
||||||
|
# todo : see if we can drop some extra attributes
|
||||||
|
# Bronze
|
||||||
|
action-setup:
|
||||||
|
status: exempt
|
||||||
|
comment: |
|
||||||
|
This integration does not provide additional actions.
|
||||||
|
appropriate-polling: done
|
||||||
|
brands: done
|
||||||
|
common-modules: done
|
||||||
|
config-flow-test-coverage:
|
||||||
|
status: todo
|
||||||
|
comment: |
|
||||||
|
test_reconfigure_api_error should use a mock config entry fixture
|
||||||
|
test_user_flow_failure should use a mock config entry fixture
|
||||||
|
move test_user_flow_* to the top of the file
|
||||||
|
config-flow: done
|
||||||
|
dependency-transparency: done
|
||||||
|
docs-actions:
|
||||||
|
status: exempt
|
||||||
|
comment: |
|
||||||
|
This integration does not provide additional actions.
|
||||||
|
docs-high-level-description: done
|
||||||
|
docs-installation-instructions: done
|
||||||
|
docs-removal-instructions: done
|
||||||
|
entity-event-setup:
|
||||||
|
status: exempt
|
||||||
|
comment: |
|
||||||
|
No events are explicitly registered by the integration.
|
||||||
|
entity-unique-id: done
|
||||||
|
has-entity-name: done
|
||||||
|
runtime-data: done
|
||||||
|
test-before-configure: done
|
||||||
|
test-before-setup: done
|
||||||
|
unique-config-entry: done
|
||||||
|
|
||||||
|
# Silver
|
||||||
|
action-exceptions: done
|
||||||
|
config-entry-unloading: done
|
||||||
|
docs-configuration-parameters: done
|
||||||
|
docs-installation-parameters: done
|
||||||
|
entity-unavailable: todo
|
||||||
|
integration-owner: done
|
||||||
|
log-when-unavailable: done
|
||||||
|
parallel-updates: todo
|
||||||
|
reauthentication-flow: todo
|
||||||
|
test-coverage:
|
||||||
|
status: todo
|
||||||
|
comment: |
|
||||||
|
test the entry state in test_failure
|
||||||
|
|
||||||
|
# Gold
|
||||||
|
devices: todo
|
||||||
|
diagnostics: todo
|
||||||
|
discovery-update-info: todo
|
||||||
|
discovery: todo
|
||||||
|
docs-data-update: done
|
||||||
|
docs-examples:
|
||||||
|
status: exempt
|
||||||
|
comment: |
|
||||||
|
This integration does not provide any automation
|
||||||
|
docs-known-limitations: todo
|
||||||
|
docs-supported-devices: todo
|
||||||
|
docs-supported-functions: done
|
||||||
|
docs-troubleshooting: done
|
||||||
|
docs-use-cases: todo
|
||||||
|
dynamic-devices: todo
|
||||||
|
entity-category: todo
|
||||||
|
entity-device-class:
|
||||||
|
status: todo
|
||||||
|
comment: change device_class=SensorDeviceClass.SIGNAL_STRENGTH to SOUND_PRESSURE
|
||||||
|
entity-disabled-by-default: todo
|
||||||
|
entity-translations: done
|
||||||
|
exception-translations: todo
|
||||||
|
icon-translations: todo
|
||||||
|
reconfiguration-flow: done
|
||||||
|
repair-issues: todo
|
||||||
|
stale-devices: todo
|
||||||
|
|
||||||
|
# Platinum
|
||||||
|
async-dependency: done
|
||||||
|
inject-websession: done
|
||||||
|
strict-typing: todo
|
||||||
@@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Awaitable, Callable
|
||||||
from typing import Literal, TypedDict
|
from typing import Literal, NotRequired, TypedDict
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ async def async_get_manager(hass: HomeAssistant) -> EnergyManager:
|
|||||||
class FlowFromGridSourceType(TypedDict):
|
class FlowFromGridSourceType(TypedDict):
|
||||||
"""Dictionary describing the 'from' stat for the grid source."""
|
"""Dictionary describing the 'from' stat for the grid source."""
|
||||||
|
|
||||||
# statistic_id of a an energy meter (kWh)
|
# statistic_id of an energy meter (kWh)
|
||||||
stat_energy_from: str
|
stat_energy_from: str
|
||||||
|
|
||||||
# statistic_id of costs ($) incurred from the energy meter
|
# statistic_id of costs ($) incurred from the energy meter
|
||||||
@@ -58,6 +58,14 @@ class FlowToGridSourceType(TypedDict):
|
|||||||
number_energy_price: float | None # Price for energy ($/kWh)
|
number_energy_price: float | None # Price for energy ($/kWh)
|
||||||
|
|
||||||
|
|
||||||
|
class GridPowerSourceType(TypedDict):
|
||||||
|
"""Dictionary holding the source of grid power consumption."""
|
||||||
|
|
||||||
|
# statistic_id of a power meter (kW)
|
||||||
|
# negative values indicate grid return
|
||||||
|
stat_rate: str
|
||||||
|
|
||||||
|
|
||||||
class GridSourceType(TypedDict):
|
class GridSourceType(TypedDict):
|
||||||
"""Dictionary holding the source of grid energy consumption."""
|
"""Dictionary holding the source of grid energy consumption."""
|
||||||
|
|
||||||
@@ -65,6 +73,7 @@ class GridSourceType(TypedDict):
|
|||||||
|
|
||||||
flow_from: list[FlowFromGridSourceType]
|
flow_from: list[FlowFromGridSourceType]
|
||||||
flow_to: list[FlowToGridSourceType]
|
flow_to: list[FlowToGridSourceType]
|
||||||
|
power: NotRequired[list[GridPowerSourceType]]
|
||||||
|
|
||||||
cost_adjustment_day: float
|
cost_adjustment_day: float
|
||||||
|
|
||||||
@@ -75,6 +84,7 @@ class SolarSourceType(TypedDict):
|
|||||||
type: Literal["solar"]
|
type: Literal["solar"]
|
||||||
|
|
||||||
stat_energy_from: str
|
stat_energy_from: str
|
||||||
|
stat_rate: NotRequired[str]
|
||||||
config_entry_solar_forecast: list[str] | None
|
config_entry_solar_forecast: list[str] | None
|
||||||
|
|
||||||
|
|
||||||
@@ -85,6 +95,8 @@ class BatterySourceType(TypedDict):
|
|||||||
|
|
||||||
stat_energy_from: str
|
stat_energy_from: str
|
||||||
stat_energy_to: str
|
stat_energy_to: str
|
||||||
|
# positive when discharging, negative when charging
|
||||||
|
stat_rate: NotRequired[str]
|
||||||
|
|
||||||
|
|
||||||
class GasSourceType(TypedDict):
|
class GasSourceType(TypedDict):
|
||||||
@@ -136,12 +148,15 @@ class DeviceConsumption(TypedDict):
|
|||||||
# This is an ever increasing value
|
# This is an ever increasing value
|
||||||
stat_consumption: str
|
stat_consumption: str
|
||||||
|
|
||||||
|
# Instantaneous rate of flow: W, L/min or m³/h
|
||||||
|
stat_rate: NotRequired[str]
|
||||||
|
|
||||||
# An optional custom name for display in energy graphs
|
# An optional custom name for display in energy graphs
|
||||||
name: str | None
|
name: str | None
|
||||||
|
|
||||||
# An optional statistic_id identifying a device
|
# An optional statistic_id identifying a device
|
||||||
# that includes this device's consumption in its total
|
# that includes this device's consumption in its total
|
||||||
included_in_stat: str | None
|
included_in_stat: NotRequired[str]
|
||||||
|
|
||||||
|
|
||||||
class EnergyPreferences(TypedDict):
|
class EnergyPreferences(TypedDict):
|
||||||
@@ -194,6 +209,12 @@ FLOW_TO_GRID_SOURCE_SCHEMA = vol.Schema(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
GRID_POWER_SOURCE_SCHEMA = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required("stat_rate"): str,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def _generate_unique_value_validator(key: str) -> Callable[[list[dict]], list[dict]]:
|
def _generate_unique_value_validator(key: str) -> Callable[[list[dict]], list[dict]]:
|
||||||
"""Generate a validator that ensures a value is only used once."""
|
"""Generate a validator that ensures a value is only used once."""
|
||||||
@@ -224,6 +245,10 @@ GRID_SOURCE_SCHEMA = vol.Schema(
|
|||||||
[FLOW_TO_GRID_SOURCE_SCHEMA],
|
[FLOW_TO_GRID_SOURCE_SCHEMA],
|
||||||
_generate_unique_value_validator("stat_energy_to"),
|
_generate_unique_value_validator("stat_energy_to"),
|
||||||
),
|
),
|
||||||
|
vol.Optional("power"): vol.All(
|
||||||
|
[GRID_POWER_SOURCE_SCHEMA],
|
||||||
|
_generate_unique_value_validator("stat_rate"),
|
||||||
|
),
|
||||||
vol.Required("cost_adjustment_day"): vol.Coerce(float),
|
vol.Required("cost_adjustment_day"): vol.Coerce(float),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -231,6 +256,7 @@ SOLAR_SOURCE_SCHEMA = vol.Schema(
|
|||||||
{
|
{
|
||||||
vol.Required("type"): "solar",
|
vol.Required("type"): "solar",
|
||||||
vol.Required("stat_energy_from"): str,
|
vol.Required("stat_energy_from"): str,
|
||||||
|
vol.Optional("stat_rate"): str,
|
||||||
vol.Optional("config_entry_solar_forecast"): vol.Any([str], None),
|
vol.Optional("config_entry_solar_forecast"): vol.Any([str], None),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -239,6 +265,7 @@ BATTERY_SOURCE_SCHEMA = vol.Schema(
|
|||||||
vol.Required("type"): "battery",
|
vol.Required("type"): "battery",
|
||||||
vol.Required("stat_energy_from"): str,
|
vol.Required("stat_energy_from"): str,
|
||||||
vol.Required("stat_energy_to"): str,
|
vol.Required("stat_energy_to"): str,
|
||||||
|
vol.Optional("stat_rate"): str,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
GAS_SOURCE_SCHEMA = vol.Schema(
|
GAS_SOURCE_SCHEMA = vol.Schema(
|
||||||
@@ -294,6 +321,7 @@ ENERGY_SOURCE_SCHEMA = vol.All(
|
|||||||
DEVICE_CONSUMPTION_SCHEMA = vol.Schema(
|
DEVICE_CONSUMPTION_SCHEMA = vol.Schema(
|
||||||
{
|
{
|
||||||
vol.Required("stat_consumption"): str,
|
vol.Required("stat_consumption"): str,
|
||||||
|
vol.Optional("stat_rate"): str,
|
||||||
vol.Optional("name"): str,
|
vol.Optional("name"): str,
|
||||||
vol.Optional("included_in_stat"): str,
|
vol.Optional("included_in_stat"): str,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from homeassistant.const import (
|
|||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
|
UnitOfPower,
|
||||||
UnitOfVolume,
|
UnitOfVolume,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback, valid_entity_id
|
from homeassistant.core import HomeAssistant, callback, valid_entity_id
|
||||||
@@ -23,12 +24,17 @@ ENERGY_USAGE_DEVICE_CLASSES = (sensor.SensorDeviceClass.ENERGY,)
|
|||||||
ENERGY_USAGE_UNITS: dict[str, tuple[UnitOfEnergy, ...]] = {
|
ENERGY_USAGE_UNITS: dict[str, tuple[UnitOfEnergy, ...]] = {
|
||||||
sensor.SensorDeviceClass.ENERGY: tuple(UnitOfEnergy)
|
sensor.SensorDeviceClass.ENERGY: tuple(UnitOfEnergy)
|
||||||
}
|
}
|
||||||
|
POWER_USAGE_DEVICE_CLASSES = (sensor.SensorDeviceClass.POWER,)
|
||||||
|
POWER_USAGE_UNITS: dict[str, tuple[UnitOfPower, ...]] = {
|
||||||
|
sensor.SensorDeviceClass.POWER: tuple(UnitOfPower)
|
||||||
|
}
|
||||||
|
|
||||||
ENERGY_PRICE_UNITS = tuple(
|
ENERGY_PRICE_UNITS = tuple(
|
||||||
f"/{unit}" for units in ENERGY_USAGE_UNITS.values() for unit in units
|
f"/{unit}" for units in ENERGY_USAGE_UNITS.values() for unit in units
|
||||||
)
|
)
|
||||||
ENERGY_UNIT_ERROR = "entity_unexpected_unit_energy"
|
ENERGY_UNIT_ERROR = "entity_unexpected_unit_energy"
|
||||||
ENERGY_PRICE_UNIT_ERROR = "entity_unexpected_unit_energy_price"
|
ENERGY_PRICE_UNIT_ERROR = "entity_unexpected_unit_energy_price"
|
||||||
|
POWER_UNIT_ERROR = "entity_unexpected_unit_power"
|
||||||
GAS_USAGE_DEVICE_CLASSES = (
|
GAS_USAGE_DEVICE_CLASSES = (
|
||||||
sensor.SensorDeviceClass.ENERGY,
|
sensor.SensorDeviceClass.ENERGY,
|
||||||
sensor.SensorDeviceClass.GAS,
|
sensor.SensorDeviceClass.GAS,
|
||||||
@@ -82,6 +88,10 @@ def _get_placeholders(hass: HomeAssistant, issue_type: str) -> dict[str, str] |
|
|||||||
f"{currency}{unit}" for unit in ENERGY_PRICE_UNITS
|
f"{currency}{unit}" for unit in ENERGY_PRICE_UNITS
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
if issue_type == POWER_UNIT_ERROR:
|
||||||
|
return {
|
||||||
|
"power_units": ", ".join(POWER_USAGE_UNITS[sensor.SensorDeviceClass.POWER]),
|
||||||
|
}
|
||||||
if issue_type == GAS_UNIT_ERROR:
|
if issue_type == GAS_UNIT_ERROR:
|
||||||
return {
|
return {
|
||||||
"energy_units": ", ".join(GAS_USAGE_UNITS[sensor.SensorDeviceClass.ENERGY]),
|
"energy_units": ", ".join(GAS_USAGE_UNITS[sensor.SensorDeviceClass.ENERGY]),
|
||||||
@@ -159,7 +169,7 @@ class EnergyPreferencesValidation:
|
|||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_validate_usage_stat(
|
def _async_validate_stat_common(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]],
|
metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]],
|
||||||
stat_id: str,
|
stat_id: str,
|
||||||
@@ -167,37 +177,41 @@ def _async_validate_usage_stat(
|
|||||||
allowed_units: Mapping[str, Sequence[str]],
|
allowed_units: Mapping[str, Sequence[str]],
|
||||||
unit_error: str,
|
unit_error: str,
|
||||||
issues: ValidationIssues,
|
issues: ValidationIssues,
|
||||||
) -> None:
|
check_negative: bool = False,
|
||||||
"""Validate a statistic."""
|
) -> str | None:
|
||||||
|
"""Validate common aspects of a statistic.
|
||||||
|
|
||||||
|
Returns the entity_id if validation succeeds, None otherwise.
|
||||||
|
"""
|
||||||
if stat_id not in metadata:
|
if stat_id not in metadata:
|
||||||
issues.add_issue(hass, "statistics_not_defined", stat_id)
|
issues.add_issue(hass, "statistics_not_defined", stat_id)
|
||||||
|
|
||||||
has_entity_source = valid_entity_id(stat_id)
|
has_entity_source = valid_entity_id(stat_id)
|
||||||
|
|
||||||
if not has_entity_source:
|
if not has_entity_source:
|
||||||
return
|
return None
|
||||||
|
|
||||||
entity_id = stat_id
|
entity_id = stat_id
|
||||||
|
|
||||||
if not recorder.is_entity_recorded(hass, entity_id):
|
if not recorder.is_entity_recorded(hass, entity_id):
|
||||||
issues.add_issue(hass, "recorder_untracked", entity_id)
|
issues.add_issue(hass, "recorder_untracked", entity_id)
|
||||||
return
|
return None
|
||||||
|
|
||||||
if (state := hass.states.get(entity_id)) is None:
|
if (state := hass.states.get(entity_id)) is None:
|
||||||
issues.add_issue(hass, "entity_not_defined", entity_id)
|
issues.add_issue(hass, "entity_not_defined", entity_id)
|
||||||
return
|
return None
|
||||||
|
|
||||||
if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN):
|
if state.state in (STATE_UNAVAILABLE, STATE_UNKNOWN):
|
||||||
issues.add_issue(hass, "entity_unavailable", entity_id, state.state)
|
issues.add_issue(hass, "entity_unavailable", entity_id, state.state)
|
||||||
return
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
current_value: float | None = float(state.state)
|
current_value: float | None = float(state.state)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
issues.add_issue(hass, "entity_state_non_numeric", entity_id, state.state)
|
issues.add_issue(hass, "entity_state_non_numeric", entity_id, state.state)
|
||||||
return
|
return None
|
||||||
|
|
||||||
if current_value is not None and current_value < 0:
|
if check_negative and current_value is not None and current_value < 0:
|
||||||
issues.add_issue(hass, "entity_negative_state", entity_id, current_value)
|
issues.add_issue(hass, "entity_negative_state", entity_id, current_value)
|
||||||
|
|
||||||
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
device_class = state.attributes.get(ATTR_DEVICE_CLASS)
|
||||||
@@ -211,6 +225,36 @@ def _async_validate_usage_stat(
|
|||||||
if device_class and unit not in allowed_units.get(device_class, []):
|
if device_class and unit not in allowed_units.get(device_class, []):
|
||||||
issues.add_issue(hass, unit_error, entity_id, unit)
|
issues.add_issue(hass, unit_error, entity_id, unit)
|
||||||
|
|
||||||
|
return entity_id
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_validate_usage_stat(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]],
|
||||||
|
stat_id: str,
|
||||||
|
allowed_device_classes: Sequence[str],
|
||||||
|
allowed_units: Mapping[str, Sequence[str]],
|
||||||
|
unit_error: str,
|
||||||
|
issues: ValidationIssues,
|
||||||
|
) -> None:
|
||||||
|
"""Validate a statistic."""
|
||||||
|
entity_id = _async_validate_stat_common(
|
||||||
|
hass,
|
||||||
|
metadata,
|
||||||
|
stat_id,
|
||||||
|
allowed_device_classes,
|
||||||
|
allowed_units,
|
||||||
|
unit_error,
|
||||||
|
issues,
|
||||||
|
check_negative=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if entity_id is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state is not None
|
||||||
state_class = state.attributes.get(sensor.ATTR_STATE_CLASS)
|
state_class = state.attributes.get(sensor.ATTR_STATE_CLASS)
|
||||||
|
|
||||||
allowed_state_classes = [
|
allowed_state_classes = [
|
||||||
@@ -255,6 +299,39 @@ def _async_validate_price_entity(
|
|||||||
issues.add_issue(hass, unit_error, entity_id, unit)
|
issues.add_issue(hass, unit_error, entity_id, unit)
|
||||||
|
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_validate_power_stat(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]],
|
||||||
|
stat_id: str,
|
||||||
|
allowed_device_classes: Sequence[str],
|
||||||
|
allowed_units: Mapping[str, Sequence[str]],
|
||||||
|
unit_error: str,
|
||||||
|
issues: ValidationIssues,
|
||||||
|
) -> None:
|
||||||
|
"""Validate a power statistic."""
|
||||||
|
entity_id = _async_validate_stat_common(
|
||||||
|
hass,
|
||||||
|
metadata,
|
||||||
|
stat_id,
|
||||||
|
allowed_device_classes,
|
||||||
|
allowed_units,
|
||||||
|
unit_error,
|
||||||
|
issues,
|
||||||
|
check_negative=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
if entity_id is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
state = hass.states.get(entity_id)
|
||||||
|
assert state is not None
|
||||||
|
state_class = state.attributes.get(sensor.ATTR_STATE_CLASS)
|
||||||
|
|
||||||
|
if state_class != sensor.SensorStateClass.MEASUREMENT:
|
||||||
|
issues.add_issue(hass, "entity_unexpected_state_class", entity_id, state_class)
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _async_validate_cost_stat(
|
def _async_validate_cost_stat(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
@@ -309,11 +386,260 @@ def _async_validate_auto_generated_cost_entity(
|
|||||||
issues.add_issue(hass, "recorder_untracked", cost_entity_id)
|
issues.add_issue(hass, "recorder_untracked", cost_entity_id)
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_grid_source(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
source: data.GridSourceType,
|
||||||
|
statistics_metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]],
|
||||||
|
wanted_statistics_metadata: set[str],
|
||||||
|
source_result: ValidationIssues,
|
||||||
|
validate_calls: list[functools.partial[None]],
|
||||||
|
) -> None:
|
||||||
|
"""Validate grid energy source."""
|
||||||
|
flow_from: data.FlowFromGridSourceType
|
||||||
|
for flow_from in source["flow_from"]:
|
||||||
|
wanted_statistics_metadata.add(flow_from["stat_energy_from"])
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_usage_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
flow_from["stat_energy_from"],
|
||||||
|
ENERGY_USAGE_DEVICE_CLASSES,
|
||||||
|
ENERGY_USAGE_UNITS,
|
||||||
|
ENERGY_UNIT_ERROR,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (stat_cost := flow_from.get("stat_cost")) is not None:
|
||||||
|
wanted_statistics_metadata.add(stat_cost)
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_cost_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
stat_cost,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif (entity_energy_price := flow_from.get("entity_energy_price")) is not None:
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_price_entity,
|
||||||
|
hass,
|
||||||
|
entity_energy_price,
|
||||||
|
source_result,
|
||||||
|
ENERGY_PRICE_UNITS,
|
||||||
|
ENERGY_PRICE_UNIT_ERROR,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
flow_from.get("entity_energy_price") is not None
|
||||||
|
or flow_from.get("number_energy_price") is not None
|
||||||
|
):
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_auto_generated_cost_entity,
|
||||||
|
hass,
|
||||||
|
flow_from["stat_energy_from"],
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
flow_to: data.FlowToGridSourceType
|
||||||
|
for flow_to in source["flow_to"]:
|
||||||
|
wanted_statistics_metadata.add(flow_to["stat_energy_to"])
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_usage_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
flow_to["stat_energy_to"],
|
||||||
|
ENERGY_USAGE_DEVICE_CLASSES,
|
||||||
|
ENERGY_USAGE_UNITS,
|
||||||
|
ENERGY_UNIT_ERROR,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (stat_compensation := flow_to.get("stat_compensation")) is not None:
|
||||||
|
wanted_statistics_metadata.add(stat_compensation)
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_cost_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
stat_compensation,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif (entity_energy_price := flow_to.get("entity_energy_price")) is not None:
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_price_entity,
|
||||||
|
hass,
|
||||||
|
entity_energy_price,
|
||||||
|
source_result,
|
||||||
|
ENERGY_PRICE_UNITS,
|
||||||
|
ENERGY_PRICE_UNIT_ERROR,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
flow_to.get("entity_energy_price") is not None
|
||||||
|
or flow_to.get("number_energy_price") is not None
|
||||||
|
):
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_auto_generated_cost_entity,
|
||||||
|
hass,
|
||||||
|
flow_to["stat_energy_to"],
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
for power_stat in source.get("power", []):
|
||||||
|
wanted_statistics_metadata.add(power_stat["stat_rate"])
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_power_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
power_stat["stat_rate"],
|
||||||
|
POWER_USAGE_DEVICE_CLASSES,
|
||||||
|
POWER_USAGE_UNITS,
|
||||||
|
POWER_UNIT_ERROR,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_gas_source(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
source: data.GasSourceType,
|
||||||
|
statistics_metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]],
|
||||||
|
wanted_statistics_metadata: set[str],
|
||||||
|
source_result: ValidationIssues,
|
||||||
|
validate_calls: list[functools.partial[None]],
|
||||||
|
) -> None:
|
||||||
|
"""Validate gas energy source."""
|
||||||
|
wanted_statistics_metadata.add(source["stat_energy_from"])
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_usage_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
source["stat_energy_from"],
|
||||||
|
GAS_USAGE_DEVICE_CLASSES,
|
||||||
|
GAS_USAGE_UNITS,
|
||||||
|
GAS_UNIT_ERROR,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (stat_cost := source.get("stat_cost")) is not None:
|
||||||
|
wanted_statistics_metadata.add(stat_cost)
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_cost_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
stat_cost,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif (entity_energy_price := source.get("entity_energy_price")) is not None:
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_price_entity,
|
||||||
|
hass,
|
||||||
|
entity_energy_price,
|
||||||
|
source_result,
|
||||||
|
GAS_PRICE_UNITS,
|
||||||
|
GAS_PRICE_UNIT_ERROR,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
source.get("entity_energy_price") is not None
|
||||||
|
or source.get("number_energy_price") is not None
|
||||||
|
):
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_auto_generated_cost_entity,
|
||||||
|
hass,
|
||||||
|
source["stat_energy_from"],
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_water_source(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
source: data.WaterSourceType,
|
||||||
|
statistics_metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]],
|
||||||
|
wanted_statistics_metadata: set[str],
|
||||||
|
source_result: ValidationIssues,
|
||||||
|
validate_calls: list[functools.partial[None]],
|
||||||
|
) -> None:
|
||||||
|
"""Validate water energy source."""
|
||||||
|
wanted_statistics_metadata.add(source["stat_energy_from"])
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_usage_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
source["stat_energy_from"],
|
||||||
|
WATER_USAGE_DEVICE_CLASSES,
|
||||||
|
WATER_USAGE_UNITS,
|
||||||
|
WATER_UNIT_ERROR,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (stat_cost := source.get("stat_cost")) is not None:
|
||||||
|
wanted_statistics_metadata.add(stat_cost)
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_cost_stat,
|
||||||
|
hass,
|
||||||
|
statistics_metadata,
|
||||||
|
stat_cost,
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif (entity_energy_price := source.get("entity_energy_price")) is not None:
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_price_entity,
|
||||||
|
hass,
|
||||||
|
entity_energy_price,
|
||||||
|
source_result,
|
||||||
|
WATER_PRICE_UNITS,
|
||||||
|
WATER_PRICE_UNIT_ERROR,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (
|
||||||
|
source.get("entity_energy_price") is not None
|
||||||
|
or source.get("number_energy_price") is not None
|
||||||
|
):
|
||||||
|
validate_calls.append(
|
||||||
|
functools.partial(
|
||||||
|
_async_validate_auto_generated_cost_entity,
|
||||||
|
hass,
|
||||||
|
source["stat_energy_from"],
|
||||||
|
source_result,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_validate(hass: HomeAssistant) -> EnergyPreferencesValidation:
|
async def async_validate(hass: HomeAssistant) -> EnergyPreferencesValidation:
|
||||||
"""Validate the energy configuration."""
|
"""Validate the energy configuration."""
|
||||||
manager: data.EnergyManager = await data.async_get_manager(hass)
|
manager: data.EnergyManager = await data.async_get_manager(hass)
|
||||||
statistics_metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]] = {}
|
statistics_metadata: dict[str, tuple[int, recorder.models.StatisticMetaData]] = {}
|
||||||
validate_calls = []
|
validate_calls: list[functools.partial[None]] = []
|
||||||
wanted_statistics_metadata: set[str] = set()
|
wanted_statistics_metadata: set[str] = set()
|
||||||
|
|
||||||
result = EnergyPreferencesValidation()
|
result = EnergyPreferencesValidation()
|
||||||
@@ -327,215 +653,35 @@ async def async_validate(hass: HomeAssistant) -> EnergyPreferencesValidation:
|
|||||||
result.energy_sources.append(source_result)
|
result.energy_sources.append(source_result)
|
||||||
|
|
||||||
if source["type"] == "grid":
|
if source["type"] == "grid":
|
||||||
flow: data.FlowFromGridSourceType | data.FlowToGridSourceType
|
_validate_grid_source(
|
||||||
for flow in source["flow_from"]:
|
hass,
|
||||||
wanted_statistics_metadata.add(flow["stat_energy_from"])
|
source,
|
||||||
validate_calls.append(
|
statistics_metadata,
|
||||||
functools.partial(
|
wanted_statistics_metadata,
|
||||||
_async_validate_usage_stat,
|
source_result,
|
||||||
hass,
|
validate_calls,
|
||||||
statistics_metadata,
|
)
|
||||||
flow["stat_energy_from"],
|
|
||||||
ENERGY_USAGE_DEVICE_CLASSES,
|
|
||||||
ENERGY_USAGE_UNITS,
|
|
||||||
ENERGY_UNIT_ERROR,
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (stat_cost := flow.get("stat_cost")) is not None:
|
|
||||||
wanted_statistics_metadata.add(stat_cost)
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_cost_stat,
|
|
||||||
hass,
|
|
||||||
statistics_metadata,
|
|
||||||
stat_cost,
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
elif (
|
|
||||||
entity_energy_price := flow.get("entity_energy_price")
|
|
||||||
) is not None:
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_price_entity,
|
|
||||||
hass,
|
|
||||||
entity_energy_price,
|
|
||||||
source_result,
|
|
||||||
ENERGY_PRICE_UNITS,
|
|
||||||
ENERGY_PRICE_UNIT_ERROR,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
|
||||||
flow.get("entity_energy_price") is not None
|
|
||||||
or flow.get("number_energy_price") is not None
|
|
||||||
):
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_auto_generated_cost_entity,
|
|
||||||
hass,
|
|
||||||
flow["stat_energy_from"],
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
for flow in source["flow_to"]:
|
|
||||||
wanted_statistics_metadata.add(flow["stat_energy_to"])
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_usage_stat,
|
|
||||||
hass,
|
|
||||||
statistics_metadata,
|
|
||||||
flow["stat_energy_to"],
|
|
||||||
ENERGY_USAGE_DEVICE_CLASSES,
|
|
||||||
ENERGY_USAGE_UNITS,
|
|
||||||
ENERGY_UNIT_ERROR,
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (stat_compensation := flow.get("stat_compensation")) is not None:
|
|
||||||
wanted_statistics_metadata.add(stat_compensation)
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_cost_stat,
|
|
||||||
hass,
|
|
||||||
statistics_metadata,
|
|
||||||
stat_compensation,
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
elif (
|
|
||||||
entity_energy_price := flow.get("entity_energy_price")
|
|
||||||
) is not None:
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_price_entity,
|
|
||||||
hass,
|
|
||||||
entity_energy_price,
|
|
||||||
source_result,
|
|
||||||
ENERGY_PRICE_UNITS,
|
|
||||||
ENERGY_PRICE_UNIT_ERROR,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
|
||||||
flow.get("entity_energy_price") is not None
|
|
||||||
or flow.get("number_energy_price") is not None
|
|
||||||
):
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_auto_generated_cost_entity,
|
|
||||||
hass,
|
|
||||||
flow["stat_energy_to"],
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
elif source["type"] == "gas":
|
elif source["type"] == "gas":
|
||||||
wanted_statistics_metadata.add(source["stat_energy_from"])
|
_validate_gas_source(
|
||||||
validate_calls.append(
|
hass,
|
||||||
functools.partial(
|
source,
|
||||||
_async_validate_usage_stat,
|
statistics_metadata,
|
||||||
hass,
|
wanted_statistics_metadata,
|
||||||
statistics_metadata,
|
source_result,
|
||||||
source["stat_energy_from"],
|
validate_calls,
|
||||||
GAS_USAGE_DEVICE_CLASSES,
|
|
||||||
GAS_USAGE_UNITS,
|
|
||||||
GAS_UNIT_ERROR,
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (stat_cost := source.get("stat_cost")) is not None:
|
|
||||||
wanted_statistics_metadata.add(stat_cost)
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_cost_stat,
|
|
||||||
hass,
|
|
||||||
statistics_metadata,
|
|
||||||
stat_cost,
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
elif (entity_energy_price := source.get("entity_energy_price")) is not None:
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_price_entity,
|
|
||||||
hass,
|
|
||||||
entity_energy_price,
|
|
||||||
source_result,
|
|
||||||
GAS_PRICE_UNITS,
|
|
||||||
GAS_PRICE_UNIT_ERROR,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
|
||||||
source.get("entity_energy_price") is not None
|
|
||||||
or source.get("number_energy_price") is not None
|
|
||||||
):
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_auto_generated_cost_entity,
|
|
||||||
hass,
|
|
||||||
source["stat_energy_from"],
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
elif source["type"] == "water":
|
elif source["type"] == "water":
|
||||||
wanted_statistics_metadata.add(source["stat_energy_from"])
|
_validate_water_source(
|
||||||
validate_calls.append(
|
hass,
|
||||||
functools.partial(
|
source,
|
||||||
_async_validate_usage_stat,
|
statistics_metadata,
|
||||||
hass,
|
wanted_statistics_metadata,
|
||||||
statistics_metadata,
|
source_result,
|
||||||
source["stat_energy_from"],
|
validate_calls,
|
||||||
WATER_USAGE_DEVICE_CLASSES,
|
|
||||||
WATER_USAGE_UNITS,
|
|
||||||
WATER_UNIT_ERROR,
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (stat_cost := source.get("stat_cost")) is not None:
|
|
||||||
wanted_statistics_metadata.add(stat_cost)
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_cost_stat,
|
|
||||||
hass,
|
|
||||||
statistics_metadata,
|
|
||||||
stat_cost,
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
elif (entity_energy_price := source.get("entity_energy_price")) is not None:
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_price_entity,
|
|
||||||
hass,
|
|
||||||
entity_energy_price,
|
|
||||||
source_result,
|
|
||||||
WATER_PRICE_UNITS,
|
|
||||||
WATER_PRICE_UNIT_ERROR,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (
|
|
||||||
source.get("entity_energy_price") is not None
|
|
||||||
or source.get("number_energy_price") is not None
|
|
||||||
):
|
|
||||||
validate_calls.append(
|
|
||||||
functools.partial(
|
|
||||||
_async_validate_auto_generated_cost_entity,
|
|
||||||
hass,
|
|
||||||
source["stat_energy_from"],
|
|
||||||
source_result,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
elif source["type"] == "solar":
|
elif source["type"] == "solar":
|
||||||
wanted_statistics_metadata.add(source["stat_energy_from"])
|
wanted_statistics_metadata.add(source["stat_energy_from"])
|
||||||
validate_calls.append(
|
validate_calls.append(
|
||||||
|
|||||||
@@ -147,6 +147,8 @@ async def async_get_config_entry_diagnostics(
|
|||||||
"ctmeter_production_phases": envoy_data.ctmeter_production_phases,
|
"ctmeter_production_phases": envoy_data.ctmeter_production_phases,
|
||||||
"ctmeter_consumption_phases": envoy_data.ctmeter_consumption_phases,
|
"ctmeter_consumption_phases": envoy_data.ctmeter_consumption_phases,
|
||||||
"ctmeter_storage_phases": envoy_data.ctmeter_storage_phases,
|
"ctmeter_storage_phases": envoy_data.ctmeter_storage_phases,
|
||||||
|
"ctmeters": envoy_data.ctmeters,
|
||||||
|
"ctmeters_phases": envoy_data.ctmeters_phases,
|
||||||
"dry_contact_status": envoy_data.dry_contact_status,
|
"dry_contact_status": envoy_data.dry_contact_status,
|
||||||
"dry_contact_settings": envoy_data.dry_contact_settings,
|
"dry_contact_settings": envoy_data.dry_contact_settings,
|
||||||
"inverters": envoy_data.inverters,
|
"inverters": envoy_data.inverters,
|
||||||
@@ -179,6 +181,7 @@ async def async_get_config_entry_diagnostics(
|
|||||||
"ct_consumption_meter": envoy.consumption_meter_type,
|
"ct_consumption_meter": envoy.consumption_meter_type,
|
||||||
"ct_production_meter": envoy.production_meter_type,
|
"ct_production_meter": envoy.production_meter_type,
|
||||||
"ct_storage_meter": envoy.storage_meter_type,
|
"ct_storage_meter": envoy.storage_meter_type,
|
||||||
|
"ct_meters": list(envoy_data.ctmeters.keys()),
|
||||||
}
|
}
|
||||||
|
|
||||||
fixture_data: dict[str, Any] = {}
|
fixture_data: dict[str, Any] = {}
|
||||||
|
|||||||
@@ -399,330 +399,189 @@ class EnvoyCTSensorEntityDescription(SensorEntityDescription):
|
|||||||
cttype: str | None = None
|
cttype: str | None = None
|
||||||
|
|
||||||
|
|
||||||
CT_NET_CONSUMPTION_SENSORS = (
|
# All ct types unified in common setup
|
||||||
EnvoyCTSensorEntityDescription(
|
CT_SENSORS = (
|
||||||
key="lifetime_net_consumption",
|
[
|
||||||
translation_key="lifetime_net_consumption",
|
EnvoyCTSensorEntityDescription(
|
||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
key=key,
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
translation_key=key,
|
||||||
device_class=SensorDeviceClass.ENERGY,
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
suggested_display_precision=3,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
value_fn=attrgetter("energy_delivered"),
|
suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
|
||||||
on_phase=None,
|
suggested_display_precision=3,
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
value_fn=attrgetter("energy_delivered"),
|
||||||
),
|
on_phase=None,
|
||||||
EnvoyCTSensorEntityDescription(
|
cttype=cttype,
|
||||||
key="lifetime_net_production",
|
)
|
||||||
translation_key="lifetime_net_production",
|
for cttype, key in (
|
||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
(CtType.NET_CONSUMPTION, "lifetime_net_consumption"),
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
# Production CT energy_delivered is not used
|
||||||
device_class=SensorDeviceClass.ENERGY,
|
(CtType.STORAGE, "lifetime_battery_discharged"),
|
||||||
suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
|
|
||||||
suggested_display_precision=3,
|
|
||||||
value_fn=attrgetter("energy_received"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="net_consumption",
|
|
||||||
translation_key="net_consumption",
|
|
||||||
native_unit_of_measurement=UnitOfPower.WATT,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
device_class=SensorDeviceClass.POWER,
|
|
||||||
suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
|
|
||||||
suggested_display_precision=3,
|
|
||||||
value_fn=attrgetter("active_power"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="frequency",
|
|
||||||
translation_key="net_ct_frequency",
|
|
||||||
native_unit_of_measurement=UnitOfFrequency.HERTZ,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
device_class=SensorDeviceClass.FREQUENCY,
|
|
||||||
suggested_display_precision=1,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("frequency"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="voltage",
|
|
||||||
translation_key="net_ct_voltage",
|
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
device_class=SensorDeviceClass.VOLTAGE,
|
|
||||||
suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
|
||||||
suggested_display_precision=1,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("voltage"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="net_ct_current",
|
|
||||||
translation_key="net_ct_current",
|
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
device_class=SensorDeviceClass.CURRENT,
|
|
||||||
suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
|
||||||
suggested_display_precision=3,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("current"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="net_ct_powerfactor",
|
|
||||||
translation_key="net_ct_powerfactor",
|
|
||||||
device_class=SensorDeviceClass.POWER_FACTOR,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
suggested_display_precision=2,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("power_factor"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="net_consumption_ct_metering_status",
|
|
||||||
translation_key="net_ct_metering_status",
|
|
||||||
device_class=SensorDeviceClass.ENUM,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
options=list(CtMeterStatus),
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("metering_status"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="net_consumption_ct_status_flags",
|
|
||||||
translation_key="net_ct_status_flags",
|
|
||||||
state_class=None,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=lambda ct: 0 if ct.status_flags is None else len(ct.status_flags),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.NET_CONSUMPTION,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
CT_NET_CONSUMPTION_PHASE_SENSORS = {
|
|
||||||
(on_phase := PHASENAMES[phase]): [
|
|
||||||
replace(
|
|
||||||
sensor,
|
|
||||||
key=f"{sensor.key}_l{phase + 1}",
|
|
||||||
translation_key=f"{sensor.translation_key}_phase",
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
on_phase=on_phase,
|
|
||||||
translation_placeholders={"phase_name": f"l{phase + 1}"},
|
|
||||||
)
|
)
|
||||||
for sensor in list(CT_NET_CONSUMPTION_SENSORS)
|
|
||||||
]
|
]
|
||||||
for phase in range(3)
|
+ [
|
||||||
}
|
EnvoyCTSensorEntityDescription(
|
||||||
|
key=key,
|
||||||
CT_PRODUCTION_SENSORS = (
|
translation_key=key,
|
||||||
EnvoyCTSensorEntityDescription(
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
key="production_ct_frequency",
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
translation_key="production_ct_frequency",
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
native_unit_of_measurement=UnitOfFrequency.HERTZ,
|
suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
suggested_display_precision=3,
|
||||||
device_class=SensorDeviceClass.FREQUENCY,
|
value_fn=attrgetter("energy_received"),
|
||||||
suggested_display_precision=1,
|
on_phase=None,
|
||||||
entity_registry_enabled_default=False,
|
cttype=cttype,
|
||||||
value_fn=attrgetter("frequency"),
|
)
|
||||||
on_phase=None,
|
for cttype, key in (
|
||||||
cttype=CtType.PRODUCTION,
|
(CtType.NET_CONSUMPTION, "lifetime_net_production"),
|
||||||
),
|
# Production CT energy_received is not used
|
||||||
EnvoyCTSensorEntityDescription(
|
(CtType.STORAGE, "lifetime_battery_charged"),
|
||||||
key="production_ct_voltage",
|
)
|
||||||
translation_key="production_ct_voltage",
|
]
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
+ [
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
EnvoyCTSensorEntityDescription(
|
||||||
device_class=SensorDeviceClass.VOLTAGE,
|
key=key,
|
||||||
suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
translation_key=key,
|
||||||
suggested_display_precision=1,
|
native_unit_of_measurement=UnitOfPower.WATT,
|
||||||
entity_registry_enabled_default=False,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
value_fn=attrgetter("voltage"),
|
device_class=SensorDeviceClass.POWER,
|
||||||
on_phase=None,
|
suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
|
||||||
cttype=CtType.PRODUCTION,
|
suggested_display_precision=3,
|
||||||
),
|
value_fn=attrgetter("active_power"),
|
||||||
EnvoyCTSensorEntityDescription(
|
on_phase=None,
|
||||||
key="production_ct_current",
|
cttype=cttype,
|
||||||
translation_key="production_ct_current",
|
)
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
for cttype, key in (
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
(CtType.NET_CONSUMPTION, "net_consumption"),
|
||||||
device_class=SensorDeviceClass.CURRENT,
|
# Production CT active_power is not used
|
||||||
suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
(CtType.STORAGE, "battery_discharge"),
|
||||||
suggested_display_precision=3,
|
)
|
||||||
entity_registry_enabled_default=False,
|
]
|
||||||
value_fn=attrgetter("current"),
|
+ [
|
||||||
on_phase=None,
|
EnvoyCTSensorEntityDescription(
|
||||||
cttype=CtType.PRODUCTION,
|
key=key,
|
||||||
),
|
translation_key=(translation_key if translation_key != "" else key),
|
||||||
EnvoyCTSensorEntityDescription(
|
native_unit_of_measurement=UnitOfFrequency.HERTZ,
|
||||||
key="production_ct_powerfactor",
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
translation_key="production_ct_powerfactor",
|
device_class=SensorDeviceClass.FREQUENCY,
|
||||||
device_class=SensorDeviceClass.POWER_FACTOR,
|
suggested_display_precision=1,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
entity_registry_enabled_default=False,
|
||||||
suggested_display_precision=2,
|
value_fn=attrgetter("frequency"),
|
||||||
entity_registry_enabled_default=False,
|
on_phase=None,
|
||||||
value_fn=attrgetter("power_factor"),
|
cttype=cttype,
|
||||||
on_phase=None,
|
)
|
||||||
cttype=CtType.PRODUCTION,
|
for cttype, key, translation_key in (
|
||||||
),
|
(CtType.NET_CONSUMPTION, "frequency", "net_ct_frequency"),
|
||||||
EnvoyCTSensorEntityDescription(
|
(CtType.PRODUCTION, "production_ct_frequency", ""),
|
||||||
key="production_ct_metering_status",
|
(CtType.STORAGE, "storage_ct_frequency", ""),
|
||||||
translation_key="production_ct_metering_status",
|
)
|
||||||
device_class=SensorDeviceClass.ENUM,
|
]
|
||||||
options=list(CtMeterStatus),
|
+ [
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
EnvoyCTSensorEntityDescription(
|
||||||
entity_registry_enabled_default=False,
|
key=key,
|
||||||
value_fn=attrgetter("metering_status"),
|
translation_key=(translation_key if translation_key != "" else key),
|
||||||
on_phase=None,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
cttype=CtType.PRODUCTION,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
EnvoyCTSensorEntityDescription(
|
suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
key="production_ct_status_flags",
|
suggested_display_precision=1,
|
||||||
translation_key="production_ct_status_flags",
|
entity_registry_enabled_default=False,
|
||||||
state_class=None,
|
value_fn=attrgetter("voltage"),
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
on_phase=None,
|
||||||
entity_registry_enabled_default=False,
|
cttype=cttype,
|
||||||
value_fn=lambda ct: 0 if ct.status_flags is None else len(ct.status_flags),
|
)
|
||||||
on_phase=None,
|
for cttype, key, translation_key in (
|
||||||
cttype=CtType.PRODUCTION,
|
(CtType.NET_CONSUMPTION, "voltage", "net_ct_voltage"),
|
||||||
),
|
(CtType.PRODUCTION, "production_ct_voltage", ""),
|
||||||
)
|
(CtType.STORAGE, "storage_voltage", "storage_ct_voltage"),
|
||||||
|
)
|
||||||
CT_PRODUCTION_PHASE_SENSORS = {
|
]
|
||||||
(on_phase := PHASENAMES[phase]): [
|
+ [
|
||||||
replace(
|
EnvoyCTSensorEntityDescription(
|
||||||
sensor,
|
key=key,
|
||||||
key=f"{sensor.key}_l{phase + 1}",
|
translation_key=key,
|
||||||
translation_key=f"{sensor.translation_key}_phase",
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
entity_registry_enabled_default=False,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
on_phase=on_phase,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
translation_placeholders={"phase_name": f"l{phase + 1}"},
|
suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
|
suggested_display_precision=3,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value_fn=attrgetter("current"),
|
||||||
|
on_phase=None,
|
||||||
|
cttype=cttype,
|
||||||
|
)
|
||||||
|
for cttype, key in (
|
||||||
|
(CtType.NET_CONSUMPTION, "net_ct_current"),
|
||||||
|
(CtType.PRODUCTION, "production_ct_current"),
|
||||||
|
(CtType.STORAGE, "storage_ct_current"),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
+ [
|
||||||
|
EnvoyCTSensorEntityDescription(
|
||||||
|
key=key,
|
||||||
|
translation_key=key,
|
||||||
|
device_class=SensorDeviceClass.POWER_FACTOR,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
suggested_display_precision=2,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value_fn=attrgetter("power_factor"),
|
||||||
|
on_phase=None,
|
||||||
|
cttype=cttype,
|
||||||
|
)
|
||||||
|
for cttype, key in (
|
||||||
|
(CtType.NET_CONSUMPTION, "net_ct_powerfactor"),
|
||||||
|
(CtType.PRODUCTION, "production_ct_powerfactor"),
|
||||||
|
(CtType.STORAGE, "storage_ct_powerfactor"),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
+ [
|
||||||
|
EnvoyCTSensorEntityDescription(
|
||||||
|
key=key,
|
||||||
|
translation_key=(translation_key if translation_key != "" else key),
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
options=list(CtMeterStatus),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value_fn=attrgetter("metering_status"),
|
||||||
|
on_phase=None,
|
||||||
|
cttype=cttype,
|
||||||
|
)
|
||||||
|
for cttype, key, translation_key in (
|
||||||
|
(
|
||||||
|
CtType.NET_CONSUMPTION,
|
||||||
|
"net_consumption_ct_metering_status",
|
||||||
|
"net_ct_metering_status",
|
||||||
|
),
|
||||||
|
(CtType.PRODUCTION, "production_ct_metering_status", ""),
|
||||||
|
(CtType.STORAGE, "storage_ct_metering_status", ""),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
+ [
|
||||||
|
EnvoyCTSensorEntityDescription(
|
||||||
|
key=key,
|
||||||
|
translation_key=(translation_key if translation_key != "" else key),
|
||||||
|
state_class=None,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value_fn=lambda ct: 0 if ct.status_flags is None else len(ct.status_flags),
|
||||||
|
on_phase=None,
|
||||||
|
cttype=cttype,
|
||||||
|
)
|
||||||
|
for cttype, key, translation_key in (
|
||||||
|
(
|
||||||
|
CtType.NET_CONSUMPTION,
|
||||||
|
"net_consumption_ct_status_flags",
|
||||||
|
"net_ct_status_flags",
|
||||||
|
),
|
||||||
|
(CtType.PRODUCTION, "production_ct_status_flags", ""),
|
||||||
|
(CtType.STORAGE, "storage_ct_status_flags", ""),
|
||||||
)
|
)
|
||||||
for sensor in list(CT_PRODUCTION_SENSORS)
|
|
||||||
]
|
]
|
||||||
for phase in range(3)
|
|
||||||
}
|
|
||||||
|
|
||||||
CT_STORAGE_SENSORS = (
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="lifetime_battery_discharged",
|
|
||||||
translation_key="lifetime_battery_discharged",
|
|
||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
|
||||||
device_class=SensorDeviceClass.ENERGY,
|
|
||||||
suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
|
|
||||||
suggested_display_precision=3,
|
|
||||||
value_fn=attrgetter("energy_delivered"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="lifetime_battery_charged",
|
|
||||||
translation_key="lifetime_battery_charged",
|
|
||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
|
||||||
state_class=SensorStateClass.TOTAL_INCREASING,
|
|
||||||
device_class=SensorDeviceClass.ENERGY,
|
|
||||||
suggested_unit_of_measurement=UnitOfEnergy.MEGA_WATT_HOUR,
|
|
||||||
suggested_display_precision=3,
|
|
||||||
value_fn=attrgetter("energy_received"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="battery_discharge",
|
|
||||||
translation_key="battery_discharge",
|
|
||||||
native_unit_of_measurement=UnitOfPower.WATT,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
device_class=SensorDeviceClass.POWER,
|
|
||||||
suggested_unit_of_measurement=UnitOfPower.KILO_WATT,
|
|
||||||
suggested_display_precision=3,
|
|
||||||
value_fn=attrgetter("active_power"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="storage_ct_frequency",
|
|
||||||
translation_key="storage_ct_frequency",
|
|
||||||
native_unit_of_measurement=UnitOfFrequency.HERTZ,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
device_class=SensorDeviceClass.FREQUENCY,
|
|
||||||
suggested_display_precision=1,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("frequency"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="storage_voltage",
|
|
||||||
translation_key="storage_ct_voltage",
|
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
device_class=SensorDeviceClass.VOLTAGE,
|
|
||||||
suggested_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
|
||||||
suggested_display_precision=1,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("voltage"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="storage_ct_current",
|
|
||||||
translation_key="storage_ct_current",
|
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
device_class=SensorDeviceClass.CURRENT,
|
|
||||||
suggested_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
|
||||||
suggested_display_precision=3,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("current"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="storage_ct_powerfactor",
|
|
||||||
translation_key="storage_ct_powerfactor",
|
|
||||||
device_class=SensorDeviceClass.POWER_FACTOR,
|
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
|
||||||
suggested_display_precision=2,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("power_factor"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="storage_ct_metering_status",
|
|
||||||
translation_key="storage_ct_metering_status",
|
|
||||||
device_class=SensorDeviceClass.ENUM,
|
|
||||||
options=list(CtMeterStatus),
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=attrgetter("metering_status"),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
EnvoyCTSensorEntityDescription(
|
|
||||||
key="storage_ct_status_flags",
|
|
||||||
translation_key="storage_ct_status_flags",
|
|
||||||
state_class=None,
|
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
|
||||||
entity_registry_enabled_default=False,
|
|
||||||
value_fn=lambda ct: 0 if ct.status_flags is None else len(ct.status_flags),
|
|
||||||
on_phase=None,
|
|
||||||
cttype=CtType.STORAGE,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
CT_STORAGE_PHASE_SENSORS = {
|
CT_PHASE_SENSORS = {
|
||||||
(on_phase := PHASENAMES[phase]): [
|
(on_phase := PHASENAMES[phase]): [
|
||||||
replace(
|
replace(
|
||||||
sensor,
|
sensor,
|
||||||
@@ -732,7 +591,7 @@ CT_STORAGE_PHASE_SENSORS = {
|
|||||||
on_phase=on_phase,
|
on_phase=on_phase,
|
||||||
translation_placeholders={"phase_name": f"l{phase + 1}"},
|
translation_placeholders={"phase_name": f"l{phase + 1}"},
|
||||||
)
|
)
|
||||||
for sensor in list(CT_STORAGE_SENSORS)
|
for sensor in list(CT_SENSORS)
|
||||||
]
|
]
|
||||||
for phase in range(3)
|
for phase in range(3)
|
||||||
}
|
}
|
||||||
@@ -1060,24 +919,14 @@ async def async_setup_entry(
|
|||||||
if envoy_data.ctmeters:
|
if envoy_data.ctmeters:
|
||||||
entities.extend(
|
entities.extend(
|
||||||
EnvoyCTEntity(coordinator, description)
|
EnvoyCTEntity(coordinator, description)
|
||||||
for sensors in (
|
for description in CT_SENSORS
|
||||||
CT_NET_CONSUMPTION_SENSORS,
|
|
||||||
CT_PRODUCTION_SENSORS,
|
|
||||||
CT_STORAGE_SENSORS,
|
|
||||||
)
|
|
||||||
for description in sensors
|
|
||||||
if description.cttype in envoy_data.ctmeters
|
if description.cttype in envoy_data.ctmeters
|
||||||
)
|
)
|
||||||
# Add Current Transformer phase entities
|
# Add Current Transformer phase entities
|
||||||
if ctmeters_phases := envoy_data.ctmeters_phases:
|
if ctmeters_phases := envoy_data.ctmeters_phases:
|
||||||
entities.extend(
|
entities.extend(
|
||||||
EnvoyCTPhaseEntity(coordinator, description)
|
EnvoyCTPhaseEntity(coordinator, description)
|
||||||
for sensors in (
|
for phase, descriptions in CT_PHASE_SENSORS.items()
|
||||||
CT_NET_CONSUMPTION_PHASE_SENSORS,
|
|
||||||
CT_PRODUCTION_PHASE_SENSORS,
|
|
||||||
CT_STORAGE_PHASE_SENSORS,
|
|
||||||
)
|
|
||||||
for phase, descriptions in sensors.items()
|
|
||||||
for description in descriptions
|
for description in descriptions
|
||||||
if (cttype := description.cttype) in ctmeters_phases
|
if (cttype := description.cttype) in ctmeters_phases
|
||||||
and phase in ctmeters_phases[cttype]
|
and phase in ctmeters_phases[cttype]
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
from urllib.parse import quote
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@@ -152,7 +153,9 @@ class HassFoscamCamera(FoscamEntity, Camera):
|
|||||||
async def stream_source(self) -> str | None:
|
async def stream_source(self) -> str | None:
|
||||||
"""Return the stream source."""
|
"""Return the stream source."""
|
||||||
if self._rtsp_port:
|
if self._rtsp_port:
|
||||||
return f"rtsp://{self._username}:{self._password}@{self._foscam_session.host}:{self._rtsp_port}/video{self._stream}"
|
_username = quote(self._username)
|
||||||
|
_password = quote(self._password)
|
||||||
|
return f"rtsp://{_username}:{_password}@{self._foscam_session.host}:{self._rtsp_port}/video{self._stream}"
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -481,6 +481,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
sidebar_title="climate",
|
sidebar_title="climate",
|
||||||
sidebar_default_visible=False,
|
sidebar_default_visible=False,
|
||||||
)
|
)
|
||||||
|
async_register_built_in_panel(
|
||||||
|
hass,
|
||||||
|
"home",
|
||||||
|
sidebar_icon="mdi:home",
|
||||||
|
sidebar_title="home",
|
||||||
|
sidebar_default_visible=False,
|
||||||
|
)
|
||||||
|
|
||||||
async_register_built_in_panel(hass, "profile")
|
async_register_built_in_panel(hass, "profile")
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/google",
|
"documentation": "https://www.home-assistant.io/integrations/google",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["googleapiclient"],
|
"loggers": ["googleapiclient"],
|
||||||
"requirements": ["gcal-sync==8.0.0", "oauth2client==4.1.3", "ical==11.0.0"]
|
"requirements": ["gcal-sync==8.0.0", "oauth2client==4.1.3", "ical==11.1.0"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,6 @@
|
|||||||
"iot_class": "cloud_push",
|
"iot_class": "cloud_push",
|
||||||
"loggers": ["aiohomeconnect"],
|
"loggers": ["aiohomeconnect"],
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
"requirements": ["aiohomeconnect==0.23.0"],
|
"requirements": ["aiohomeconnect==0.23.1"],
|
||||||
"zeroconf": ["_homeconnect._tcp.local."]
|
"zeroconf": ["_homeconnect._tcp.local."]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -412,8 +412,8 @@ class HomeConnectProgramSelectEntity(HomeConnectEntity, SelectEntity):
|
|||||||
"""Set the program value."""
|
"""Set the program value."""
|
||||||
event = self.appliance.events.get(cast(EventKey, self.bsh_key))
|
event = self.appliance.events.get(cast(EventKey, self.bsh_key))
|
||||||
self._attr_current_option = (
|
self._attr_current_option = (
|
||||||
PROGRAMS_TRANSLATION_KEYS_MAP.get(cast(ProgramKey, event.value))
|
PROGRAMS_TRANSLATION_KEYS_MAP.get(ProgramKey(event_value))
|
||||||
if event
|
if event and isinstance(event_value := event.value, str)
|
||||||
else None
|
else None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -556,8 +556,11 @@ class HomeConnectSensor(HomeConnectEntity, SensorEntity):
|
|||||||
status = self.appliance.status[cast(StatusKey, self.bsh_key)].value
|
status = self.appliance.status[cast(StatusKey, self.bsh_key)].value
|
||||||
self._update_native_value(status)
|
self._update_native_value(status)
|
||||||
|
|
||||||
def _update_native_value(self, status: str | float) -> None:
|
def _update_native_value(self, status: str | float | None) -> None:
|
||||||
"""Set the value of the sensor based on the given value."""
|
"""Set the value of the sensor based on the given value."""
|
||||||
|
if status is None:
|
||||||
|
self._attr_native_value = None
|
||||||
|
return
|
||||||
match self.device_class:
|
match self.device_class:
|
||||||
case SensorDeviceClass.TIMESTAMP:
|
case SensorDeviceClass.TIMESTAMP:
|
||||||
self._attr_native_value = dt_util.utcnow() + timedelta(
|
self._attr_native_value = dt_util.utcnow() + timedelta(
|
||||||
|
|||||||
@@ -76,9 +76,18 @@ class ZBT2FirmwareMixin(ConfigEntryBaseFlow, FirmwareInstallFlowProtocol):
|
|||||||
"""Mixin for Home Assistant Connect ZBT-2 firmware methods."""
|
"""Mixin for Home Assistant Connect ZBT-2 firmware methods."""
|
||||||
|
|
||||||
context: ConfigFlowContext
|
context: ConfigFlowContext
|
||||||
BOOTLOADER_RESET_METHODS = [ResetTarget.RTS_DTR]
|
|
||||||
ZIGBEE_BAUDRATE = 460800
|
ZIGBEE_BAUDRATE = 460800
|
||||||
|
|
||||||
|
# Early ZBT-2 samples used RTS/DTR to trigger the bootloader, later ones use the
|
||||||
|
# baudrate method. Since the two are mutually exclusive we just use both.
|
||||||
|
BOOTLOADER_RESET_METHODS = [ResetTarget.RTS_DTR, ResetTarget.BAUDRATE]
|
||||||
|
APPLICATION_PROBE_METHODS = [
|
||||||
|
(ApplicationType.GECKO_BOOTLOADER, 115200),
|
||||||
|
(ApplicationType.EZSP, ZIGBEE_BAUDRATE),
|
||||||
|
(ApplicationType.SPINEL, 460800),
|
||||||
|
]
|
||||||
|
|
||||||
async def async_step_install_zigbee_firmware(
|
async def async_step_install_zigbee_firmware(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
|
|||||||
@@ -6,6 +6,12 @@
|
|||||||
"dependencies": ["hardware", "usb", "homeassistant_hardware"],
|
"dependencies": ["hardware", "usb", "homeassistant_hardware"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/homeassistant_connect_zbt2",
|
"documentation": "https://www.home-assistant.io/integrations/homeassistant_connect_zbt2",
|
||||||
"integration_type": "hardware",
|
"integration_type": "hardware",
|
||||||
|
"loggers": [
|
||||||
|
"bellows",
|
||||||
|
"universal_silabs_flasher",
|
||||||
|
"zigpy.serial",
|
||||||
|
"serial_asyncio_fast"
|
||||||
|
],
|
||||||
"quality_scale": "bronze",
|
"quality_scale": "bronze",
|
||||||
"usb": [
|
"usb": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from homeassistant.components.homeassistant_hardware.update import (
|
|||||||
from homeassistant.components.homeassistant_hardware.util import (
|
from homeassistant.components.homeassistant_hardware.util import (
|
||||||
ApplicationType,
|
ApplicationType,
|
||||||
FirmwareInfo,
|
FirmwareInfo,
|
||||||
ResetTarget,
|
|
||||||
)
|
)
|
||||||
from homeassistant.components.update import UpdateDeviceClass
|
from homeassistant.components.update import UpdateDeviceClass
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
@@ -24,6 +23,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import HomeAssistantConnectZBT2ConfigEntry
|
from . import HomeAssistantConnectZBT2ConfigEntry
|
||||||
|
from .config_flow import ZBT2FirmwareMixin
|
||||||
from .const import DOMAIN, FIRMWARE, FIRMWARE_VERSION, HARDWARE_NAME, SERIAL_NUMBER
|
from .const import DOMAIN, FIRMWARE, FIRMWARE_VERSION, HARDWARE_NAME, SERIAL_NUMBER
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -134,7 +134,8 @@ async def async_setup_entry(
|
|||||||
class FirmwareUpdateEntity(BaseFirmwareUpdateEntity):
|
class FirmwareUpdateEntity(BaseFirmwareUpdateEntity):
|
||||||
"""Connect ZBT-2 firmware update entity."""
|
"""Connect ZBT-2 firmware update entity."""
|
||||||
|
|
||||||
bootloader_reset_methods = [ResetTarget.RTS_DTR]
|
BOOTLOADER_RESET_METHODS = ZBT2FirmwareMixin.BOOTLOADER_RESET_METHODS
|
||||||
|
APPLICATION_PROBE_METHODS = ZBT2FirmwareMixin.APPLICATION_PROBE_METHODS
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class BaseFirmwareInstallFlow(ConfigEntryBaseFlow, ABC):
|
|||||||
|
|
||||||
ZIGBEE_BAUDRATE = 115200 # Default, subclasses may override
|
ZIGBEE_BAUDRATE = 115200 # Default, subclasses may override
|
||||||
BOOTLOADER_RESET_METHODS: list[ResetTarget] = [] # Default, subclasses may override
|
BOOTLOADER_RESET_METHODS: list[ResetTarget] = [] # Default, subclasses may override
|
||||||
|
APPLICATION_PROBE_METHODS: list[tuple[ApplicationType, int]] = []
|
||||||
|
|
||||||
_picked_firmware_type: PickedFirmwareType
|
_picked_firmware_type: PickedFirmwareType
|
||||||
_zigbee_flow_strategy: ZigbeeFlowStrategy = ZigbeeFlowStrategy.RECOMMENDED
|
_zigbee_flow_strategy: ZigbeeFlowStrategy = ZigbeeFlowStrategy.RECOMMENDED
|
||||||
@@ -230,7 +231,11 @@ class BaseFirmwareInstallFlow(ConfigEntryBaseFlow, ABC):
|
|||||||
# Installing new firmware is only truly required if the wrong type is
|
# Installing new firmware is only truly required if the wrong type is
|
||||||
# installed: upgrading to the latest release of the current firmware type
|
# installed: upgrading to the latest release of the current firmware type
|
||||||
# isn't strictly necessary for functionality.
|
# isn't strictly necessary for functionality.
|
||||||
self._probed_firmware_info = await probe_silabs_firmware_info(self._device)
|
self._probed_firmware_info = await probe_silabs_firmware_info(
|
||||||
|
self._device,
|
||||||
|
bootloader_reset_methods=self.BOOTLOADER_RESET_METHODS,
|
||||||
|
application_probe_methods=self.APPLICATION_PROBE_METHODS,
|
||||||
|
)
|
||||||
|
|
||||||
firmware_install_required = self._probed_firmware_info is None or (
|
firmware_install_required = self._probed_firmware_info is None or (
|
||||||
self._probed_firmware_info.firmware_type != expected_installed_firmware_type
|
self._probed_firmware_info.firmware_type != expected_installed_firmware_type
|
||||||
@@ -295,6 +300,7 @@ class BaseFirmwareInstallFlow(ConfigEntryBaseFlow, ABC):
|
|||||||
fw_data=fw_data,
|
fw_data=fw_data,
|
||||||
expected_installed_firmware_type=expected_installed_firmware_type,
|
expected_installed_firmware_type=expected_installed_firmware_type,
|
||||||
bootloader_reset_methods=self.BOOTLOADER_RESET_METHODS,
|
bootloader_reset_methods=self.BOOTLOADER_RESET_METHODS,
|
||||||
|
application_probe_methods=self.APPLICATION_PROBE_METHODS,
|
||||||
progress_callback=lambda offset, total: self.async_update_progress(
|
progress_callback=lambda offset, total: self.async_update_progress(
|
||||||
offset / total
|
offset / total
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/homeassistant_hardware",
|
"documentation": "https://www.home-assistant.io/integrations/homeassistant_hardware",
|
||||||
"integration_type": "system",
|
"integration_type": "system",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"universal-silabs-flasher==0.0.37",
|
"universal-silabs-flasher==0.1.0",
|
||||||
"ha-silabs-firmware-client==0.3.0"
|
"ha-silabs-firmware-client==0.3.0"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ class BaseFirmwareUpdateEntity(
|
|||||||
|
|
||||||
# Subclasses provide the mapping between firmware types and entity descriptions
|
# Subclasses provide the mapping between firmware types and entity descriptions
|
||||||
entity_description: FirmwareUpdateEntityDescription
|
entity_description: FirmwareUpdateEntityDescription
|
||||||
bootloader_reset_methods: list[ResetTarget] = []
|
BOOTLOADER_RESET_METHODS: list[ResetTarget]
|
||||||
|
APPLICATION_PROBE_METHODS: list[tuple[ApplicationType, int]]
|
||||||
|
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
UpdateEntityFeature.INSTALL | UpdateEntityFeature.PROGRESS
|
UpdateEntityFeature.INSTALL | UpdateEntityFeature.PROGRESS
|
||||||
@@ -278,7 +279,8 @@ class BaseFirmwareUpdateEntity(
|
|||||||
device=self._current_device,
|
device=self._current_device,
|
||||||
fw_data=fw_data,
|
fw_data=fw_data,
|
||||||
expected_installed_firmware_type=self.entity_description.expected_firmware_type,
|
expected_installed_firmware_type=self.entity_description.expected_firmware_type,
|
||||||
bootloader_reset_methods=self.bootloader_reset_methods,
|
bootloader_reset_methods=self.BOOTLOADER_RESET_METHODS,
|
||||||
|
application_probe_methods=self.APPLICATION_PROBE_METHODS,
|
||||||
progress_callback=self._update_progress,
|
progress_callback=self._update_progress,
|
||||||
domain=self._config_entry.domain,
|
domain=self._config_entry.domain,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from collections.abc import AsyncIterator, Callable, Iterable, Sequence
|
from collections.abc import AsyncIterator, Callable, Sequence
|
||||||
from contextlib import AsyncExitStack, asynccontextmanager
|
from contextlib import AsyncExitStack, asynccontextmanager
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
@@ -309,15 +309,20 @@ async def guess_firmware_info(hass: HomeAssistant, device_path: str) -> Firmware
|
|||||||
|
|
||||||
|
|
||||||
async def probe_silabs_firmware_info(
|
async def probe_silabs_firmware_info(
|
||||||
device: str, *, probe_methods: Iterable[ApplicationType] | None = None
|
device: str,
|
||||||
|
*,
|
||||||
|
bootloader_reset_methods: Sequence[ResetTarget],
|
||||||
|
application_probe_methods: Sequence[tuple[ApplicationType, int]],
|
||||||
) -> FirmwareInfo | None:
|
) -> FirmwareInfo | None:
|
||||||
"""Probe the running firmware on a SiLabs device."""
|
"""Probe the running firmware on a SiLabs device."""
|
||||||
flasher = Flasher(
|
flasher = Flasher(
|
||||||
device=device,
|
device=device,
|
||||||
**(
|
probe_methods=tuple(
|
||||||
{"probe_methods": [m.as_flasher_application_type() for m in probe_methods]}
|
(m.as_flasher_application_type(), baudrate)
|
||||||
if probe_methods
|
for m, baudrate in application_probe_methods
|
||||||
else {}
|
),
|
||||||
|
bootloader_reset=tuple(
|
||||||
|
m.as_flasher_reset_target() for m in bootloader_reset_methods
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -343,11 +348,18 @@ async def probe_silabs_firmware_info(
|
|||||||
|
|
||||||
|
|
||||||
async def probe_silabs_firmware_type(
|
async def probe_silabs_firmware_type(
|
||||||
device: str, *, probe_methods: Iterable[ApplicationType] | None = None
|
device: str,
|
||||||
|
*,
|
||||||
|
bootloader_reset_methods: Sequence[ResetTarget],
|
||||||
|
application_probe_methods: Sequence[tuple[ApplicationType, int]],
|
||||||
) -> ApplicationType | None:
|
) -> ApplicationType | None:
|
||||||
"""Probe the running firmware type on a SiLabs device."""
|
"""Probe the running firmware type on a SiLabs device."""
|
||||||
|
|
||||||
fw_info = await probe_silabs_firmware_info(device, probe_methods=probe_methods)
|
fw_info = await probe_silabs_firmware_info(
|
||||||
|
device,
|
||||||
|
bootloader_reset_methods=bootloader_reset_methods,
|
||||||
|
application_probe_methods=application_probe_methods,
|
||||||
|
)
|
||||||
if fw_info is None:
|
if fw_info is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -359,12 +371,22 @@ async def async_flash_silabs_firmware(
|
|||||||
device: str,
|
device: str,
|
||||||
fw_data: bytes,
|
fw_data: bytes,
|
||||||
expected_installed_firmware_type: ApplicationType,
|
expected_installed_firmware_type: ApplicationType,
|
||||||
bootloader_reset_methods: Sequence[ResetTarget] = (),
|
bootloader_reset_methods: Sequence[ResetTarget],
|
||||||
|
application_probe_methods: Sequence[tuple[ApplicationType, int]],
|
||||||
progress_callback: Callable[[int, int], None] | None = None,
|
progress_callback: Callable[[int, int], None] | None = None,
|
||||||
*,
|
*,
|
||||||
domain: str = DOMAIN,
|
domain: str = DOMAIN,
|
||||||
) -> FirmwareInfo:
|
) -> FirmwareInfo:
|
||||||
"""Flash firmware to the SiLabs device."""
|
"""Flash firmware to the SiLabs device."""
|
||||||
|
if not any(
|
||||||
|
method == expected_installed_firmware_type
|
||||||
|
for method, _ in application_probe_methods
|
||||||
|
):
|
||||||
|
raise ValueError(
|
||||||
|
f"Expected installed firmware type {expected_installed_firmware_type!r}"
|
||||||
|
f" not in application probe methods {application_probe_methods!r}"
|
||||||
|
)
|
||||||
|
|
||||||
async with async_firmware_update_context(hass, device, domain):
|
async with async_firmware_update_context(hass, device, domain):
|
||||||
firmware_info = await guess_firmware_info(hass, device)
|
firmware_info = await guess_firmware_info(hass, device)
|
||||||
_LOGGER.debug("Identified firmware info: %s", firmware_info)
|
_LOGGER.debug("Identified firmware info: %s", firmware_info)
|
||||||
@@ -373,11 +395,9 @@ async def async_flash_silabs_firmware(
|
|||||||
|
|
||||||
flasher = Flasher(
|
flasher = Flasher(
|
||||||
device=device,
|
device=device,
|
||||||
probe_methods=(
|
probe_methods=tuple(
|
||||||
ApplicationType.GECKO_BOOTLOADER.as_flasher_application_type(),
|
(m.as_flasher_application_type(), baudrate)
|
||||||
ApplicationType.EZSP.as_flasher_application_type(),
|
for m, baudrate in application_probe_methods
|
||||||
ApplicationType.SPINEL.as_flasher_application_type(),
|
|
||||||
ApplicationType.CPC.as_flasher_application_type(),
|
|
||||||
),
|
),
|
||||||
bootloader_reset=tuple(
|
bootloader_reset=tuple(
|
||||||
m.as_flasher_reset_target() for m in bootloader_reset_methods
|
m.as_flasher_reset_target() for m in bootloader_reset_methods
|
||||||
@@ -401,7 +421,13 @@ async def async_flash_silabs_firmware(
|
|||||||
|
|
||||||
probed_firmware_info = await probe_silabs_firmware_info(
|
probed_firmware_info = await probe_silabs_firmware_info(
|
||||||
device,
|
device,
|
||||||
probe_methods=(expected_installed_firmware_type,),
|
bootloader_reset_methods=bootloader_reset_methods,
|
||||||
|
# Only probe for the expected installed firmware type
|
||||||
|
application_probe_methods=[
|
||||||
|
(method, baudrate)
|
||||||
|
for method, baudrate in application_probe_methods
|
||||||
|
if method == expected_installed_firmware_type
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
if probed_firmware_info is None:
|
if probed_firmware_info is None:
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from homeassistant.components.homeassistant_hardware.helpers import (
|
|||||||
from homeassistant.components.homeassistant_hardware.util import (
|
from homeassistant.components.homeassistant_hardware.util import (
|
||||||
ApplicationType,
|
ApplicationType,
|
||||||
FirmwareInfo,
|
FirmwareInfo,
|
||||||
|
ResetTarget,
|
||||||
)
|
)
|
||||||
from homeassistant.components.usb import (
|
from homeassistant.components.usb import (
|
||||||
usb_service_info_from_device,
|
usb_service_info_from_device,
|
||||||
@@ -79,6 +80,20 @@ class SkyConnectFirmwareMixin(ConfigEntryBaseFlow, FirmwareInstallFlowProtocol):
|
|||||||
|
|
||||||
context: ConfigFlowContext
|
context: ConfigFlowContext
|
||||||
|
|
||||||
|
ZIGBEE_BAUDRATE = 115200
|
||||||
|
# There is no hardware bootloader trigger
|
||||||
|
BOOTLOADER_RESET_METHODS: list[ResetTarget] = []
|
||||||
|
APPLICATION_PROBE_METHODS = [
|
||||||
|
(ApplicationType.GECKO_BOOTLOADER, 115200),
|
||||||
|
(ApplicationType.EZSP, ZIGBEE_BAUDRATE),
|
||||||
|
(ApplicationType.SPINEL, 460800),
|
||||||
|
# CPC baudrates can be removed once multiprotocol is removed
|
||||||
|
(ApplicationType.CPC, 115200),
|
||||||
|
(ApplicationType.CPC, 230400),
|
||||||
|
(ApplicationType.CPC, 460800),
|
||||||
|
(ApplicationType.ROUTER, 115200),
|
||||||
|
]
|
||||||
|
|
||||||
def _get_translation_placeholders(self) -> dict[str, str]:
|
def _get_translation_placeholders(self) -> dict[str, str]:
|
||||||
"""Shared translation placeholders."""
|
"""Shared translation placeholders."""
|
||||||
placeholders = {
|
placeholders = {
|
||||||
|
|||||||
@@ -6,6 +6,12 @@
|
|||||||
"dependencies": ["hardware", "usb", "homeassistant_hardware"],
|
"dependencies": ["hardware", "usb", "homeassistant_hardware"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/homeassistant_sky_connect",
|
"documentation": "https://www.home-assistant.io/integrations/homeassistant_sky_connect",
|
||||||
"integration_type": "hardware",
|
"integration_type": "hardware",
|
||||||
|
"loggers": [
|
||||||
|
"bellows",
|
||||||
|
"universal_silabs_flasher",
|
||||||
|
"zigpy.serial",
|
||||||
|
"serial_asyncio_fast"
|
||||||
|
],
|
||||||
"usb": [
|
"usb": [
|
||||||
{
|
{
|
||||||
"description": "*skyconnect v1.0*",
|
"description": "*skyconnect v1.0*",
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import HomeAssistantSkyConnectConfigEntry
|
from . import HomeAssistantSkyConnectConfigEntry
|
||||||
|
from .config_flow import SkyConnectFirmwareMixin
|
||||||
from .const import (
|
from .const import (
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
FIRMWARE,
|
FIRMWARE,
|
||||||
@@ -151,8 +152,8 @@ async def async_setup_entry(
|
|||||||
class FirmwareUpdateEntity(BaseFirmwareUpdateEntity):
|
class FirmwareUpdateEntity(BaseFirmwareUpdateEntity):
|
||||||
"""SkyConnect firmware update entity."""
|
"""SkyConnect firmware update entity."""
|
||||||
|
|
||||||
# The ZBT-1 does not have a hardware bootloader trigger
|
BOOTLOADER_RESET_METHODS = SkyConnectFirmwareMixin.BOOTLOADER_RESET_METHODS
|
||||||
bootloader_reset_methods = []
|
APPLICATION_PROBE_METHODS = SkyConnectFirmwareMixin.APPLICATION_PROBE_METHODS
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -82,7 +82,18 @@ else:
|
|||||||
class YellowFirmwareMixin(ConfigEntryBaseFlow, FirmwareInstallFlowProtocol):
|
class YellowFirmwareMixin(ConfigEntryBaseFlow, FirmwareInstallFlowProtocol):
|
||||||
"""Mixin for Home Assistant Yellow firmware methods."""
|
"""Mixin for Home Assistant Yellow firmware methods."""
|
||||||
|
|
||||||
|
ZIGBEE_BAUDRATE = 115200
|
||||||
BOOTLOADER_RESET_METHODS = [ResetTarget.YELLOW]
|
BOOTLOADER_RESET_METHODS = [ResetTarget.YELLOW]
|
||||||
|
APPLICATION_PROBE_METHODS = [
|
||||||
|
(ApplicationType.GECKO_BOOTLOADER, 115200),
|
||||||
|
(ApplicationType.EZSP, ZIGBEE_BAUDRATE),
|
||||||
|
(ApplicationType.SPINEL, 460800),
|
||||||
|
# CPC baudrates can be removed once multiprotocol is removed
|
||||||
|
(ApplicationType.CPC, 115200),
|
||||||
|
(ApplicationType.CPC, 230400),
|
||||||
|
(ApplicationType.CPC, 460800),
|
||||||
|
(ApplicationType.ROUTER, 115200),
|
||||||
|
]
|
||||||
|
|
||||||
async def async_step_install_zigbee_firmware(
|
async def async_step_install_zigbee_firmware(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
@@ -146,7 +157,11 @@ class HomeAssistantYellowConfigFlow(
|
|||||||
assert self._device is not None
|
assert self._device is not None
|
||||||
|
|
||||||
# We do not actually use any portion of `BaseFirmwareConfigFlow` beyond this
|
# We do not actually use any portion of `BaseFirmwareConfigFlow` beyond this
|
||||||
self._probed_firmware_info = await probe_silabs_firmware_info(self._device)
|
self._probed_firmware_info = await probe_silabs_firmware_info(
|
||||||
|
self._device,
|
||||||
|
bootloader_reset_methods=self.BOOTLOADER_RESET_METHODS,
|
||||||
|
application_probe_methods=self.APPLICATION_PROBE_METHODS,
|
||||||
|
)
|
||||||
|
|
||||||
# Kick off ZHA hardware discovery automatically if Zigbee firmware is running
|
# Kick off ZHA hardware discovery automatically if Zigbee firmware is running
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -7,5 +7,11 @@
|
|||||||
"dependencies": ["hardware", "homeassistant_hardware"],
|
"dependencies": ["hardware", "homeassistant_hardware"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/homeassistant_yellow",
|
"documentation": "https://www.home-assistant.io/integrations/homeassistant_yellow",
|
||||||
"integration_type": "hardware",
|
"integration_type": "hardware",
|
||||||
|
"loggers": [
|
||||||
|
"bellows",
|
||||||
|
"universal_silabs_flasher",
|
||||||
|
"zigpy.serial",
|
||||||
|
"serial_asyncio_fast"
|
||||||
|
],
|
||||||
"single_config_entry": true
|
"single_config_entry": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ from homeassistant.components.homeassistant_hardware.update import (
|
|||||||
from homeassistant.components.homeassistant_hardware.util import (
|
from homeassistant.components.homeassistant_hardware.util import (
|
||||||
ApplicationType,
|
ApplicationType,
|
||||||
FirmwareInfo,
|
FirmwareInfo,
|
||||||
ResetTarget,
|
|
||||||
)
|
)
|
||||||
from homeassistant.components.update import UpdateDeviceClass
|
from homeassistant.components.update import UpdateDeviceClass
|
||||||
from homeassistant.const import EntityCategory
|
from homeassistant.const import EntityCategory
|
||||||
@@ -24,6 +23,7 @@ from homeassistant.helpers.device_registry import DeviceInfo
|
|||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import HomeAssistantYellowConfigEntry
|
from . import HomeAssistantYellowConfigEntry
|
||||||
|
from .config_flow import YellowFirmwareMixin
|
||||||
from .const import DOMAIN, FIRMWARE, FIRMWARE_VERSION, MANUFACTURER, MODEL, RADIO_DEVICE
|
from .const import DOMAIN, FIRMWARE, FIRMWARE_VERSION, MANUFACTURER, MODEL, RADIO_DEVICE
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@@ -150,7 +150,8 @@ async def async_setup_entry(
|
|||||||
class FirmwareUpdateEntity(BaseFirmwareUpdateEntity):
|
class FirmwareUpdateEntity(BaseFirmwareUpdateEntity):
|
||||||
"""Yellow firmware update entity."""
|
"""Yellow firmware update entity."""
|
||||||
|
|
||||||
bootloader_reset_methods = [ResetTarget.YELLOW] # Triggers a GPIO reset
|
BOOTLOADER_RESET_METHODS = YellowFirmwareMixin.BOOTLOADER_RESET_METHODS
|
||||||
|
APPLICATION_PROBE_METHODS = YellowFirmwareMixin.APPLICATION_PROBE_METHODS
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|||||||
@@ -37,5 +37,5 @@
|
|||||||
"iot_class": "cloud_push",
|
"iot_class": "cloud_push",
|
||||||
"loggers": ["pylamarzocco"],
|
"loggers": ["pylamarzocco"],
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
"requirements": ["pylamarzocco==2.1.2"]
|
"requirements": ["pylamarzocco==2.1.3"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ class LaMarzoccoUpdateEntity(LaMarzoccoEntity, UpdateEntity):
|
|||||||
await self.coordinator.device.update_firmware()
|
await self.coordinator.device.update_firmware()
|
||||||
while (
|
while (
|
||||||
update_progress := await self.coordinator.device.get_firmware()
|
update_progress := await self.coordinator.device.get_firmware()
|
||||||
).command_status is UpdateStatus.IN_PROGRESS:
|
).command_status is not UpdateStatus.UPDATED:
|
||||||
if counter >= MAX_UPDATE_WAIT:
|
if counter >= MAX_UPDATE_WAIT:
|
||||||
_raise_timeout_error()
|
_raise_timeout_error()
|
||||||
self._attr_update_percentage = update_progress.progress_percentage
|
self._attr_update_percentage = update_progress.progress_percentage
|
||||||
|
|||||||
@@ -7,5 +7,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/local_calendar",
|
"documentation": "https://www.home-assistant.io/integrations/local_calendar",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["ical"],
|
"loggers": ["ical"],
|
||||||
"requirements": ["ical==11.0.0"]
|
"requirements": ["ical==11.1.0"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,5 +5,5 @@
|
|||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/local_todo",
|
"documentation": "https://www.home-assistant.io/integrations/local_todo",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"requirements": ["ical==11.0.0"]
|
"requirements": ["ical==11.1.0"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@
|
|||||||
"integration_type": "hub",
|
"integration_type": "hub",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"quality_scale": "silver",
|
"quality_scale": "silver",
|
||||||
"requirements": ["lunatone-rest-api-client==0.5.3"]
|
"requirements": ["lunatone-rest-api-client==0.5.7"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/mill",
|
"documentation": "https://www.home-assistant.io/integrations/mill",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["mill", "mill_local"],
|
"loggers": ["mill", "mill_local"],
|
||||||
"requirements": ["millheater==0.14.0", "mill-local==0.3.0"]
|
"requirements": ["millheater==0.14.1", "mill-local==0.3.0"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,10 +61,12 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
async_add_entities([MobileAppBinarySensor(data, config_entry)])
|
async_add_entities([MobileAppBinarySensor(data, config_entry)])
|
||||||
|
|
||||||
async_dispatcher_connect(
|
config_entry.async_on_unload(
|
||||||
hass,
|
async_dispatcher_connect(
|
||||||
f"{DOMAIN}_{ENTITY_TYPE}_register",
|
hass,
|
||||||
handle_sensor_registration,
|
f"{DOMAIN}_{ENTITY_TYPE}_register",
|
||||||
|
handle_sensor_registration,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -72,10 +72,12 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
async_add_entities([MobileAppSensor(data, config_entry)])
|
async_add_entities([MobileAppSensor(data, config_entry)])
|
||||||
|
|
||||||
async_dispatcher_connect(
|
config_entry.async_on_unload(
|
||||||
hass,
|
async_dispatcher_connect(
|
||||||
f"{DOMAIN}_{ENTITY_TYPE}_register",
|
hass,
|
||||||
handle_sensor_registration,
|
f"{DOMAIN}_{ENTITY_TYPE}_register",
|
||||||
|
handle_sensor_registration,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
"message": "Cannot read {filename}, no access to path; `allowlist_external_dirs` may need to be adjusted in `configuration.yaml`"
|
"message": "Cannot read {filename}, no access to path; `allowlist_external_dirs` may need to be adjusted in `configuration.yaml`"
|
||||||
},
|
},
|
||||||
"oauth2_implementation_unavailable": {
|
"oauth2_implementation_unavailable": {
|
||||||
"message": "OAuth2 implementation unavailable, will retry"
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
},
|
},
|
||||||
"update_failed": {
|
"update_failed": {
|
||||||
"message": "Failed to update drive state"
|
"message": "Failed to update drive state"
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
"oauth2_implementation_unavailable": {
|
"oauth2_implementation_unavailable": {
|
||||||
"message": "OAuth2 implementation unavailable, will retry"
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from sqlalchemy.orm import DeclarativeBase
|
|||||||
from sqlalchemy.orm.attributes import InstrumentedAttribute
|
from sqlalchemy.orm.attributes import InstrumentedAttribute
|
||||||
|
|
||||||
from ..const import SupportedDialect
|
from ..const import SupportedDialect
|
||||||
from ..db_schema import DOUBLE_PRECISION_TYPE_SQL, DOUBLE_TYPE
|
from ..db_schema import DOUBLE_PRECISION_TYPE_SQL, DOUBLE_TYPE, MYSQL_COLLATE
|
||||||
from ..util import session_scope
|
from ..util import session_scope
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@@ -105,12 +105,13 @@ def _validate_table_schema_has_correct_collation(
|
|||||||
or dialect_kwargs.get("mariadb_collate")
|
or dialect_kwargs.get("mariadb_collate")
|
||||||
or connection.dialect._fetch_setting(connection, "collation_server") # type: ignore[attr-defined] # noqa: SLF001
|
or connection.dialect._fetch_setting(connection, "collation_server") # type: ignore[attr-defined] # noqa: SLF001
|
||||||
)
|
)
|
||||||
if collate and collate != "utf8mb4_unicode_ci":
|
if collate and collate != MYSQL_COLLATE:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"Database %s collation is not utf8mb4_unicode_ci",
|
"Database %s collation is not %s",
|
||||||
table,
|
table,
|
||||||
|
MYSQL_COLLATE,
|
||||||
)
|
)
|
||||||
schema_errors.add(f"{table}.utf8mb4_unicode_ci")
|
schema_errors.add(f"{table}.{MYSQL_COLLATE}")
|
||||||
return schema_errors
|
return schema_errors
|
||||||
|
|
||||||
|
|
||||||
@@ -240,7 +241,7 @@ def correct_db_schema_utf8(
|
|||||||
table_name = table_object.__tablename__
|
table_name = table_object.__tablename__
|
||||||
if (
|
if (
|
||||||
f"{table_name}.4-byte UTF-8" in schema_errors
|
f"{table_name}.4-byte UTF-8" in schema_errors
|
||||||
or f"{table_name}.utf8mb4_unicode_ci" in schema_errors
|
or f"{table_name}.{MYSQL_COLLATE}" in schema_errors
|
||||||
):
|
):
|
||||||
from ..migration import ( # noqa: PLC0415
|
from ..migration import ( # noqa: PLC0415
|
||||||
_correct_table_character_set_and_collation,
|
_correct_table_character_set_and_collation,
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ class LegacyBase(DeclarativeBase):
|
|||||||
"""Base class for tables, used for schema migration."""
|
"""Base class for tables, used for schema migration."""
|
||||||
|
|
||||||
|
|
||||||
SCHEMA_VERSION = 52
|
SCHEMA_VERSION = 53
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ LEGACY_STATES_ENTITY_ID_LAST_UPDATED_TS_INDEX = "ix_states_entity_id_last_update
|
|||||||
LEGACY_MAX_LENGTH_EVENT_CONTEXT_ID: Final = 36
|
LEGACY_MAX_LENGTH_EVENT_CONTEXT_ID: Final = 36
|
||||||
CONTEXT_ID_BIN_MAX_LENGTH = 16
|
CONTEXT_ID_BIN_MAX_LENGTH = 16
|
||||||
|
|
||||||
MYSQL_COLLATE = "utf8mb4_unicode_ci"
|
MYSQL_COLLATE = "utf8mb4_bin"
|
||||||
MYSQL_DEFAULT_CHARSET = "utf8mb4"
|
MYSQL_DEFAULT_CHARSET = "utf8mb4"
|
||||||
MYSQL_ENGINE = "InnoDB"
|
MYSQL_ENGINE = "InnoDB"
|
||||||
|
|
||||||
|
|||||||
@@ -1361,7 +1361,7 @@ class _SchemaVersion20Migrator(_SchemaVersionMigrator, target_version=20):
|
|||||||
class _SchemaVersion21Migrator(_SchemaVersionMigrator, target_version=21):
|
class _SchemaVersion21Migrator(_SchemaVersionMigrator, target_version=21):
|
||||||
def _apply_update(self) -> None:
|
def _apply_update(self) -> None:
|
||||||
"""Version specific update method."""
|
"""Version specific update method."""
|
||||||
# Try to change the character set of the statistic_meta table
|
# Try to change the character set of events, states and statistics_meta tables
|
||||||
if self.engine.dialect.name == SupportedDialect.MYSQL:
|
if self.engine.dialect.name == SupportedDialect.MYSQL:
|
||||||
for table in ("events", "states", "statistics_meta"):
|
for table in ("events", "states", "statistics_meta"):
|
||||||
_correct_table_character_set_and_collation(table, self.session_maker)
|
_correct_table_character_set_and_collation(table, self.session_maker)
|
||||||
@@ -2125,6 +2125,23 @@ class _SchemaVersion52Migrator(_SchemaVersionMigrator, target_version=52):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class _SchemaVersion53Migrator(_SchemaVersionMigrator, target_version=53):
|
||||||
|
def _apply_update(self) -> None:
|
||||||
|
"""Version specific update method."""
|
||||||
|
# Try to change the character set of events, states and statistics_meta tables
|
||||||
|
if self.engine.dialect.name == SupportedDialect.MYSQL:
|
||||||
|
for table in (
|
||||||
|
"events",
|
||||||
|
"event_data",
|
||||||
|
"states",
|
||||||
|
"state_attributes",
|
||||||
|
"statistics",
|
||||||
|
"statistics_meta",
|
||||||
|
"statistics_short_term",
|
||||||
|
):
|
||||||
|
_correct_table_character_set_and_collation(table, self.session_maker)
|
||||||
|
|
||||||
|
|
||||||
def _migrate_statistics_columns_to_timestamp_removing_duplicates(
|
def _migrate_statistics_columns_to_timestamp_removing_duplicates(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
instance: Recorder,
|
instance: Recorder,
|
||||||
@@ -2167,8 +2184,10 @@ def _correct_table_character_set_and_collation(
|
|||||||
"""Correct issues detected by validate_db_schema."""
|
"""Correct issues detected by validate_db_schema."""
|
||||||
# Attempt to convert the table to utf8mb4
|
# Attempt to convert the table to utf8mb4
|
||||||
_LOGGER.warning(
|
_LOGGER.warning(
|
||||||
"Updating character set and collation of table %s to utf8mb4. %s",
|
"Updating table %s to character set %s and collation %s. %s",
|
||||||
table,
|
table,
|
||||||
|
MYSQL_DEFAULT_CHARSET,
|
||||||
|
MYSQL_COLLATE,
|
||||||
MIGRATION_NOTE_MINUTES,
|
MIGRATION_NOTE_MINUTES,
|
||||||
)
|
)
|
||||||
with (
|
with (
|
||||||
|
|||||||
@@ -8,5 +8,5 @@
|
|||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["ical"],
|
"loggers": ["ical"],
|
||||||
"quality_scale": "silver",
|
"quality_scale": "silver",
|
||||||
"requirements": ["ical==11.0.0"]
|
"requirements": ["ical==11.1.0"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up Ruuvitag BLE device from a config entry."""
|
"""Set up Ruuvi BLE device from a config entry."""
|
||||||
address = entry.unique_id
|
address = entry.unique_id
|
||||||
assert address is not None
|
assert address is not None
|
||||||
data = RuuvitagBluetoothDeviceData()
|
data = RuuvitagBluetoothDeviceData()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"domain": "ruuvitag_ble",
|
"domain": "ruuvitag_ble",
|
||||||
"name": "RuuviTag BLE",
|
"name": "Ruuvi BLE",
|
||||||
"bluetooth": [
|
"bluetooth": [
|
||||||
{
|
{
|
||||||
"connectable": false,
|
"connectable": false,
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ async def async_setup_entry(
|
|||||||
entry: config_entries.ConfigEntry,
|
entry: config_entries.ConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Ruuvitag BLE sensors."""
|
"""Set up the Ruuvi BLE sensors."""
|
||||||
coordinator: PassiveBluetoothProcessorCoordinator = hass.data[DOMAIN][
|
coordinator: PassiveBluetoothProcessorCoordinator = hass.data[DOMAIN][
|
||||||
entry.entry_id
|
entry.entry_id
|
||||||
]
|
]
|
||||||
@@ -210,7 +210,7 @@ class RuuvitagBluetoothSensorEntity(
|
|||||||
],
|
],
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
):
|
):
|
||||||
"""Representation of a Ruuvitag BLE sensor."""
|
"""Representation of a Ruuvi BLE sensor."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> int | float | None:
|
def native_value(self) -> int | float | None:
|
||||||
|
|||||||
@@ -3,10 +3,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import OrderedDict
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from satel_integra.satel_integra import AlarmState
|
from satel_integra.satel_integra import AlarmState, AsyncSatel
|
||||||
|
|
||||||
from homeassistant.components.alarm_control_panel import (
|
from homeassistant.components.alarm_control_panel import (
|
||||||
AlarmControlPanelEntity,
|
AlarmControlPanelEntity,
|
||||||
@@ -14,7 +13,7 @@ from homeassistant.components.alarm_control_panel import (
|
|||||||
AlarmControlPanelState,
|
AlarmControlPanelState,
|
||||||
CodeFormat,
|
CodeFormat,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.config_entries import ConfigSubentry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
@@ -26,6 +25,19 @@ from .const import (
|
|||||||
SUBENTRY_TYPE_PARTITION,
|
SUBENTRY_TYPE_PARTITION,
|
||||||
SatelConfigEntry,
|
SatelConfigEntry,
|
||||||
)
|
)
|
||||||
|
from .entity import SatelIntegraEntity
|
||||||
|
|
||||||
|
ALARM_STATE_MAP = {
|
||||||
|
AlarmState.TRIGGERED: AlarmControlPanelState.TRIGGERED,
|
||||||
|
AlarmState.TRIGGERED_FIRE: AlarmControlPanelState.TRIGGERED,
|
||||||
|
AlarmState.ENTRY_TIME: AlarmControlPanelState.PENDING,
|
||||||
|
AlarmState.ARMED_MODE3: AlarmControlPanelState.ARMED_HOME,
|
||||||
|
AlarmState.ARMED_MODE2: AlarmControlPanelState.ARMED_HOME,
|
||||||
|
AlarmState.ARMED_MODE1: AlarmControlPanelState.ARMED_HOME,
|
||||||
|
AlarmState.ARMED_MODE0: AlarmControlPanelState.ARMED_AWAY,
|
||||||
|
AlarmState.EXIT_COUNTDOWN_OVER_10: AlarmControlPanelState.ARMING,
|
||||||
|
AlarmState.EXIT_COUNTDOWN_UNDER_10: AlarmControlPanelState.ARMING,
|
||||||
|
}
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -45,48 +57,54 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
for subentry in partition_subentries:
|
for subentry in partition_subentries:
|
||||||
partition_num = subentry.data[CONF_PARTITION_NUMBER]
|
partition_num: int = subentry.data[CONF_PARTITION_NUMBER]
|
||||||
zone_name = subentry.data[CONF_NAME]
|
arm_home_mode: int = subentry.data[CONF_ARM_HOME_MODE]
|
||||||
arm_home_mode = subentry.data[CONF_ARM_HOME_MODE]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
SatelIntegraAlarmPanel(
|
SatelIntegraAlarmPanel(
|
||||||
controller,
|
controller,
|
||||||
zone_name,
|
|
||||||
arm_home_mode,
|
|
||||||
partition_num,
|
|
||||||
config_entry.entry_id,
|
config_entry.entry_id,
|
||||||
|
subentry,
|
||||||
|
partition_num,
|
||||||
|
arm_home_mode,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
config_subentry_id=subentry.subentry_id,
|
config_subentry_id=subentry.subentry_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SatelIntegraAlarmPanel(AlarmControlPanelEntity):
|
class SatelIntegraAlarmPanel(SatelIntegraEntity, AlarmControlPanelEntity):
|
||||||
"""Representation of an AlarmDecoder-based alarm panel."""
|
"""Representation of an AlarmDecoder-based alarm panel."""
|
||||||
|
|
||||||
_attr_code_format = CodeFormat.NUMBER
|
_attr_code_format = CodeFormat.NUMBER
|
||||||
_attr_should_poll = False
|
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
AlarmControlPanelEntityFeature.ARM_HOME
|
AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
| AlarmControlPanelEntityFeature.ARM_AWAY
|
| AlarmControlPanelEntityFeature.ARM_AWAY
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, controller, name, arm_home_mode, partition_id, config_entry_id
|
self,
|
||||||
|
controller: AsyncSatel,
|
||||||
|
config_entry_id: str,
|
||||||
|
subentry: ConfigSubentry,
|
||||||
|
device_number: int,
|
||||||
|
arm_home_mode: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the alarm panel."""
|
"""Initialize the alarm panel."""
|
||||||
self._attr_name = name
|
super().__init__(
|
||||||
self._attr_unique_id = f"{config_entry_id}_alarm_panel_{partition_id}"
|
controller,
|
||||||
|
config_entry_id,
|
||||||
|
subentry,
|
||||||
|
device_number,
|
||||||
|
)
|
||||||
|
|
||||||
self._arm_home_mode = arm_home_mode
|
self._arm_home_mode = arm_home_mode
|
||||||
self._partition_id = partition_id
|
|
||||||
self._satel = controller
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Update alarm status and register callbacks for future updates."""
|
"""Update alarm status and register callbacks for future updates."""
|
||||||
_LOGGER.debug("Starts listening for panel messages")
|
self._attr_alarm_state = self._read_alarm_state()
|
||||||
self._update_alarm_status()
|
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
self.hass, SIGNAL_PANEL_MESSAGE, self._update_alarm_status
|
self.hass, SIGNAL_PANEL_MESSAGE, self._update_alarm_status
|
||||||
@@ -94,55 +112,29 @@ class SatelIntegraAlarmPanel(AlarmControlPanelEntity):
|
|||||||
)
|
)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def _update_alarm_status(self):
|
def _update_alarm_status(self) -> None:
|
||||||
"""Handle alarm status update."""
|
"""Handle alarm status update."""
|
||||||
state = self._read_alarm_state()
|
state = self._read_alarm_state()
|
||||||
_LOGGER.debug("Got status update, current status: %s", state)
|
|
||||||
if state != self._attr_alarm_state:
|
if state != self._attr_alarm_state:
|
||||||
self._attr_alarm_state = state
|
self._attr_alarm_state = state
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
else:
|
|
||||||
_LOGGER.debug("Ignoring alarm status message, same state")
|
|
||||||
|
|
||||||
def _read_alarm_state(self):
|
def _read_alarm_state(self) -> AlarmControlPanelState | None:
|
||||||
"""Read current status of the alarm and translate it into HA status."""
|
"""Read current status of the alarm and translate it into HA status."""
|
||||||
|
|
||||||
# Default - disarmed:
|
|
||||||
hass_alarm_status = AlarmControlPanelState.DISARMED
|
|
||||||
|
|
||||||
if not self._satel.connected:
|
if not self._satel.connected:
|
||||||
|
_LOGGER.debug("Alarm panel not connected")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
state_map = OrderedDict(
|
for satel_state, ha_state in ALARM_STATE_MAP.items():
|
||||||
[
|
|
||||||
(AlarmState.TRIGGERED, AlarmControlPanelState.TRIGGERED),
|
|
||||||
(AlarmState.TRIGGERED_FIRE, AlarmControlPanelState.TRIGGERED),
|
|
||||||
(AlarmState.ENTRY_TIME, AlarmControlPanelState.PENDING),
|
|
||||||
(AlarmState.ARMED_MODE3, AlarmControlPanelState.ARMED_HOME),
|
|
||||||
(AlarmState.ARMED_MODE2, AlarmControlPanelState.ARMED_HOME),
|
|
||||||
(AlarmState.ARMED_MODE1, AlarmControlPanelState.ARMED_HOME),
|
|
||||||
(AlarmState.ARMED_MODE0, AlarmControlPanelState.ARMED_AWAY),
|
|
||||||
(
|
|
||||||
AlarmState.EXIT_COUNTDOWN_OVER_10,
|
|
||||||
AlarmControlPanelState.PENDING,
|
|
||||||
),
|
|
||||||
(
|
|
||||||
AlarmState.EXIT_COUNTDOWN_UNDER_10,
|
|
||||||
AlarmControlPanelState.PENDING,
|
|
||||||
),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
_LOGGER.debug("State map of Satel: %s", self._satel.partition_states)
|
|
||||||
|
|
||||||
for satel_state, ha_state in state_map.items():
|
|
||||||
if (
|
if (
|
||||||
satel_state in self._satel.partition_states
|
satel_state in self._satel.partition_states
|
||||||
and self._partition_id in self._satel.partition_states[satel_state]
|
and self._device_number in self._satel.partition_states[satel_state]
|
||||||
):
|
):
|
||||||
hass_alarm_status = ha_state
|
return ha_state
|
||||||
break
|
|
||||||
|
|
||||||
return hass_alarm_status
|
return AlarmControlPanelState.DISARMED
|
||||||
|
|
||||||
async def async_alarm_disarm(self, code: str | None = None) -> None:
|
async def async_alarm_disarm(self, code: str | None = None) -> None:
|
||||||
"""Send disarm command."""
|
"""Send disarm command."""
|
||||||
@@ -154,25 +146,21 @@ class SatelIntegraAlarmPanel(AlarmControlPanelEntity):
|
|||||||
self._attr_alarm_state == AlarmControlPanelState.TRIGGERED
|
self._attr_alarm_state == AlarmControlPanelState.TRIGGERED
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER.debug("Disarming, self._attr_alarm_state: %s", self._attr_alarm_state)
|
await self._satel.disarm(code, [self._device_number])
|
||||||
|
|
||||||
await self._satel.disarm(code, [self._partition_id])
|
|
||||||
|
|
||||||
if clear_alarm_necessary:
|
if clear_alarm_necessary:
|
||||||
# Wait 1s before clearing the alarm
|
# Wait 1s before clearing the alarm
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
await self._satel.clear_alarm(code, [self._partition_id])
|
await self._satel.clear_alarm(code, [self._device_number])
|
||||||
|
|
||||||
async def async_alarm_arm_away(self, code: str | None = None) -> None:
|
async def async_alarm_arm_away(self, code: str | None = None) -> None:
|
||||||
"""Send arm away command."""
|
"""Send arm away command."""
|
||||||
_LOGGER.debug("Arming away")
|
|
||||||
|
|
||||||
if code:
|
if code:
|
||||||
await self._satel.arm(code, [self._partition_id])
|
await self._satel.arm(code, [self._device_number])
|
||||||
|
|
||||||
async def async_alarm_arm_home(self, code: str | None = None) -> None:
|
async def async_alarm_arm_home(self, code: str | None = None) -> None:
|
||||||
"""Send arm home command."""
|
"""Send arm home command."""
|
||||||
_LOGGER.debug("Arming home")
|
|
||||||
|
|
||||||
if code:
|
if code:
|
||||||
await self._satel.arm(code, [self._partition_id], self._arm_home_mode)
|
await self._satel.arm(code, [self._device_number], self._arm_home_mode)
|
||||||
|
|||||||
@@ -8,25 +8,22 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import CONF_NAME
|
from homeassistant.config_entries import ConfigSubentry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_OUTPUT_NUMBER,
|
CONF_OUTPUT_NUMBER,
|
||||||
CONF_OUTPUTS,
|
|
||||||
CONF_ZONE_NUMBER,
|
CONF_ZONE_NUMBER,
|
||||||
CONF_ZONE_TYPE,
|
CONF_ZONE_TYPE,
|
||||||
CONF_ZONES,
|
|
||||||
DOMAIN,
|
|
||||||
SIGNAL_OUTPUTS_UPDATED,
|
SIGNAL_OUTPUTS_UPDATED,
|
||||||
SIGNAL_ZONES_UPDATED,
|
SIGNAL_ZONES_UPDATED,
|
||||||
SUBENTRY_TYPE_OUTPUT,
|
SUBENTRY_TYPE_OUTPUT,
|
||||||
SUBENTRY_TYPE_ZONE,
|
SUBENTRY_TYPE_ZONE,
|
||||||
SatelConfigEntry,
|
SatelConfigEntry,
|
||||||
)
|
)
|
||||||
|
from .entity import SatelIntegraEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@@ -46,18 +43,16 @@ async def async_setup_entry(
|
|||||||
for subentry in zone_subentries:
|
for subentry in zone_subentries:
|
||||||
zone_num: int = subentry.data[CONF_ZONE_NUMBER]
|
zone_num: int = subentry.data[CONF_ZONE_NUMBER]
|
||||||
zone_type: BinarySensorDeviceClass = subentry.data[CONF_ZONE_TYPE]
|
zone_type: BinarySensorDeviceClass = subentry.data[CONF_ZONE_TYPE]
|
||||||
zone_name: str = subentry.data[CONF_NAME]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
SatelIntegraBinarySensor(
|
SatelIntegraBinarySensor(
|
||||||
controller,
|
controller,
|
||||||
zone_num,
|
|
||||||
zone_name,
|
|
||||||
zone_type,
|
|
||||||
CONF_ZONES,
|
|
||||||
SIGNAL_ZONES_UPDATED,
|
|
||||||
config_entry.entry_id,
|
config_entry.entry_id,
|
||||||
|
subentry,
|
||||||
|
zone_num,
|
||||||
|
zone_type,
|
||||||
|
SIGNAL_ZONES_UPDATED,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
config_subentry_id=subentry.subentry_id,
|
config_subentry_id=subentry.subentry_id,
|
||||||
@@ -71,51 +66,44 @@ async def async_setup_entry(
|
|||||||
for subentry in output_subentries:
|
for subentry in output_subentries:
|
||||||
output_num: int = subentry.data[CONF_OUTPUT_NUMBER]
|
output_num: int = subentry.data[CONF_OUTPUT_NUMBER]
|
||||||
ouput_type: BinarySensorDeviceClass = subentry.data[CONF_ZONE_TYPE]
|
ouput_type: BinarySensorDeviceClass = subentry.data[CONF_ZONE_TYPE]
|
||||||
output_name: str = subentry.data[CONF_NAME]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
SatelIntegraBinarySensor(
|
SatelIntegraBinarySensor(
|
||||||
controller,
|
controller,
|
||||||
output_num,
|
|
||||||
output_name,
|
|
||||||
ouput_type,
|
|
||||||
CONF_OUTPUTS,
|
|
||||||
SIGNAL_OUTPUTS_UPDATED,
|
|
||||||
config_entry.entry_id,
|
config_entry.entry_id,
|
||||||
|
subentry,
|
||||||
|
output_num,
|
||||||
|
ouput_type,
|
||||||
|
SIGNAL_OUTPUTS_UPDATED,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
config_subentry_id=subentry.subentry_id,
|
config_subentry_id=subentry.subentry_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SatelIntegraBinarySensor(BinarySensorEntity):
|
class SatelIntegraBinarySensor(SatelIntegraEntity, BinarySensorEntity):
|
||||||
"""Representation of an Satel Integra binary sensor."""
|
"""Representation of an Satel Integra binary sensor."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
controller: AsyncSatel,
|
controller: AsyncSatel,
|
||||||
device_number: int,
|
|
||||||
device_name: str,
|
|
||||||
device_class: BinarySensorDeviceClass,
|
|
||||||
sensor_type: str,
|
|
||||||
react_to_signal: str,
|
|
||||||
config_entry_id: str,
|
config_entry_id: str,
|
||||||
|
subentry: ConfigSubentry,
|
||||||
|
device_number: int,
|
||||||
|
device_class: BinarySensorDeviceClass,
|
||||||
|
react_to_signal: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the binary_sensor."""
|
"""Initialize the binary_sensor."""
|
||||||
self._device_number = device_number
|
super().__init__(
|
||||||
self._attr_unique_id = f"{config_entry_id}_{sensor_type}_{device_number}"
|
controller,
|
||||||
self._react_to_signal = react_to_signal
|
config_entry_id,
|
||||||
self._satel = controller
|
subentry,
|
||||||
|
device_number,
|
||||||
|
)
|
||||||
|
|
||||||
self._attr_device_class = device_class
|
self._attr_device_class = device_class
|
||||||
self._attr_device_info = DeviceInfo(
|
self._react_to_signal = react_to_signal
|
||||||
name=device_name, identifiers={(DOMAIN, self._attr_unique_id)}
|
|
||||||
)
|
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
|
|||||||
58
homeassistant/components/satel_integra/entity.py
Normal file
58
homeassistant/components/satel_integra/entity.py
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
"""Satel Integra base entity."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from satel_integra.satel_integra import AsyncSatel
|
||||||
|
|
||||||
|
from homeassistant.config_entries import ConfigSubentry
|
||||||
|
from homeassistant.const import CONF_NAME
|
||||||
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
|
from .const import (
|
||||||
|
DOMAIN,
|
||||||
|
SUBENTRY_TYPE_OUTPUT,
|
||||||
|
SUBENTRY_TYPE_PARTITION,
|
||||||
|
SUBENTRY_TYPE_SWITCHABLE_OUTPUT,
|
||||||
|
SUBENTRY_TYPE_ZONE,
|
||||||
|
)
|
||||||
|
|
||||||
|
SubentryTypeToEntityType: dict[str, str] = {
|
||||||
|
SUBENTRY_TYPE_PARTITION: "alarm_panel",
|
||||||
|
SUBENTRY_TYPE_SWITCHABLE_OUTPUT: "switch",
|
||||||
|
SUBENTRY_TYPE_ZONE: "zones",
|
||||||
|
SUBENTRY_TYPE_OUTPUT: "outputs",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class SatelIntegraEntity(Entity):
|
||||||
|
"""Defines a base Satel Integra entity."""
|
||||||
|
|
||||||
|
_attr_should_poll = False
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
controller: AsyncSatel,
|
||||||
|
config_entry_id: str,
|
||||||
|
subentry: ConfigSubentry,
|
||||||
|
device_number: int,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the Satel Integra entity."""
|
||||||
|
|
||||||
|
self._satel = controller
|
||||||
|
self._device_number = device_number
|
||||||
|
|
||||||
|
entity_type = SubentryTypeToEntityType[subentry.subentry_type]
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert entity_type is not None
|
||||||
|
|
||||||
|
self._attr_unique_id = f"{config_entry_id}_{entity_type}_{device_number}"
|
||||||
|
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
name=subentry.data[CONF_NAME], identifiers={(DOMAIN, self._attr_unique_id)}
|
||||||
|
)
|
||||||
@@ -7,19 +7,19 @@ from typing import Any
|
|||||||
from satel_integra.satel_integra import AsyncSatel
|
from satel_integra.satel_integra import AsyncSatel
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
from homeassistant.components.switch import SwitchEntity
|
||||||
from homeassistant.const import CONF_CODE, CONF_NAME
|
from homeassistant.config_entries import ConfigSubentry
|
||||||
|
from homeassistant.const import CONF_CODE
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_SWITCHABLE_OUTPUT_NUMBER,
|
CONF_SWITCHABLE_OUTPUT_NUMBER,
|
||||||
DOMAIN,
|
|
||||||
SIGNAL_OUTPUTS_UPDATED,
|
SIGNAL_OUTPUTS_UPDATED,
|
||||||
SUBENTRY_TYPE_SWITCHABLE_OUTPUT,
|
SUBENTRY_TYPE_SWITCHABLE_OUTPUT,
|
||||||
SatelConfigEntry,
|
SatelConfigEntry,
|
||||||
)
|
)
|
||||||
|
from .entity import SatelIntegraEntity
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@@ -38,47 +38,42 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
for subentry in switchable_output_subentries:
|
for subentry in switchable_output_subentries:
|
||||||
switchable_output_num: int = subentry.data[CONF_SWITCHABLE_OUTPUT_NUMBER]
|
switchable_output_num: int = subentry.data[CONF_SWITCHABLE_OUTPUT_NUMBER]
|
||||||
switchable_output_name: str = subentry.data[CONF_NAME]
|
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
SatelIntegraSwitch(
|
SatelIntegraSwitch(
|
||||||
controller,
|
controller,
|
||||||
switchable_output_num,
|
|
||||||
switchable_output_name,
|
|
||||||
config_entry.options.get(CONF_CODE),
|
|
||||||
config_entry.entry_id,
|
config_entry.entry_id,
|
||||||
|
subentry,
|
||||||
|
switchable_output_num,
|
||||||
|
config_entry.options.get(CONF_CODE),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
config_subentry_id=subentry.subentry_id,
|
config_subentry_id=subentry.subentry_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class SatelIntegraSwitch(SwitchEntity):
|
class SatelIntegraSwitch(SatelIntegraEntity, SwitchEntity):
|
||||||
"""Representation of an Satel switch."""
|
"""Representation of an Satel Integra switch."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
|
||||||
_attr_has_entity_name = True
|
|
||||||
_attr_name = None
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
controller: AsyncSatel,
|
controller: AsyncSatel,
|
||||||
device_number: int,
|
|
||||||
device_name: str,
|
|
||||||
code: str | None,
|
|
||||||
config_entry_id: str,
|
config_entry_id: str,
|
||||||
|
subentry: ConfigSubentry,
|
||||||
|
device_number: int,
|
||||||
|
code: str | None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the switch."""
|
"""Initialize the switch."""
|
||||||
self._device_number = device_number
|
super().__init__(
|
||||||
self._attr_unique_id = f"{config_entry_id}_switch_{device_number}"
|
controller,
|
||||||
self._code = code
|
config_entry_id,
|
||||||
self._satel = controller
|
subentry,
|
||||||
|
device_number,
|
||||||
self._attr_device_info = DeviceInfo(
|
|
||||||
name=device_name, identifiers={(DOMAIN, self._attr_unique_id)}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self._code = code
|
||||||
|
|
||||||
async def async_added_to_hass(self) -> None:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Register callbacks."""
|
"""Register callbacks."""
|
||||||
self._attr_is_on = self._device_number in self._satel.violated_outputs
|
self._attr_is_on = self._device_number in self._satel.violated_outputs
|
||||||
|
|||||||
@@ -118,6 +118,9 @@
|
|||||||
"pm25": {
|
"pm25": {
|
||||||
"default": "mdi:molecule"
|
"default": "mdi:molecule"
|
||||||
},
|
},
|
||||||
|
"pm4": {
|
||||||
|
"default": "mdi:molecule"
|
||||||
|
},
|
||||||
"power": {
|
"power": {
|
||||||
"default": "mdi:flash"
|
"default": "mdi:flash"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,15 +3,17 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
from http import HTTPStatus
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from aiosenz import SENZAPI, Thermostat
|
from aiosenz import SENZAPI, Thermostat
|
||||||
from httpx import RequestError
|
from httpx import HTTPStatusError, RequestError
|
||||||
|
import jwt
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv, httpx_client
|
from homeassistant.helpers import config_validation as cv, httpx_client
|
||||||
from homeassistant.helpers.config_entry_oauth2_flow import (
|
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||||
ImplementationUnavailableError,
|
ImplementationUnavailableError,
|
||||||
@@ -32,9 +34,10 @@ CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
|||||||
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
PLATFORMS = [Platform.CLIMATE, Platform.SENSOR]
|
||||||
|
|
||||||
type SENZDataUpdateCoordinator = DataUpdateCoordinator[dict[str, Thermostat]]
|
type SENZDataUpdateCoordinator = DataUpdateCoordinator[dict[str, Thermostat]]
|
||||||
|
type SENZConfigEntry = ConfigEntry[SENZDataUpdateCoordinator]
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: SENZConfigEntry) -> bool:
|
||||||
"""Set up SENZ from a config entry."""
|
"""Set up SENZ from a config entry."""
|
||||||
try:
|
try:
|
||||||
implementation = await async_get_config_entry_implementation(hass, entry)
|
implementation = await async_get_config_entry_implementation(hass, entry)
|
||||||
@@ -57,8 +60,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
account = await senz_api.get_account()
|
account = await senz_api.get_account()
|
||||||
|
except HTTPStatusError as err:
|
||||||
|
if err.response.status_code == HTTPStatus.UNAUTHORIZED:
|
||||||
|
raise ConfigEntryAuthFailed(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="config_entry_auth_failed",
|
||||||
|
) from err
|
||||||
|
raise ConfigEntryNotReady(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="config_entry_not_ready",
|
||||||
|
) from err
|
||||||
except RequestError as err:
|
except RequestError as err:
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="config_entry_not_ready",
|
||||||
|
) from err
|
||||||
|
|
||||||
coordinator: SENZDataUpdateCoordinator = DataUpdateCoordinator(
|
coordinator: SENZDataUpdateCoordinator = DataUpdateCoordinator(
|
||||||
hass,
|
hass,
|
||||||
@@ -71,16 +87,37 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator
|
entry.runtime_data = coordinator
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: SENZConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
|
||||||
|
|
||||||
return unload_ok
|
|
||||||
|
async def async_migrate_entry(
|
||||||
|
hass: HomeAssistant, config_entry: SENZConfigEntry
|
||||||
|
) -> bool:
|
||||||
|
"""Migrate old entry."""
|
||||||
|
|
||||||
|
# Use sub(ject) from access_token as unique_id
|
||||||
|
if config_entry.version == 1 and config_entry.minor_version == 1:
|
||||||
|
token = jwt.decode(
|
||||||
|
config_entry.data["token"]["access_token"],
|
||||||
|
options={"verify_signature": False},
|
||||||
|
)
|
||||||
|
uid = token["sub"]
|
||||||
|
hass.config_entries.async_update_entry(
|
||||||
|
config_entry, unique_id=uid, minor_version=2
|
||||||
|
)
|
||||||
|
_LOGGER.info(
|
||||||
|
"Migration to version %s.%s successful",
|
||||||
|
config_entry.version,
|
||||||
|
config_entry.minor_version,
|
||||||
|
)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|||||||
@@ -12,24 +12,23 @@ from homeassistant.components.climate import (
|
|||||||
HVACAction,
|
HVACAction,
|
||||||
HVACMode,
|
HVACMode,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature
|
from homeassistant.const import ATTR_TEMPERATURE, PRECISION_TENTHS, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import SENZDataUpdateCoordinator
|
from . import SENZConfigEntry, SENZDataUpdateCoordinator
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: SENZConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the SENZ climate entities from a config entry."""
|
"""Set up the SENZ climate entities from a config entry."""
|
||||||
coordinator: SENZDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
SENZClimate(thermostat, coordinator) for thermostat in coordinator.data.values()
|
SENZClimate(thermostat, coordinator) for thermostat in coordinator.data.values()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
"""Config flow for nVent RAYCHEM SENZ."""
|
"""Config flow for nVent RAYCHEM SENZ."""
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
import logging
|
import logging
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
import jwt
|
||||||
|
|
||||||
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
|
||||||
from homeassistant.helpers import config_entry_oauth2_flow
|
from homeassistant.helpers import config_entry_oauth2_flow
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
@@ -12,6 +17,8 @@ class OAuth2FlowHandler(
|
|||||||
):
|
):
|
||||||
"""Config flow to handle SENZ OAuth2 authentication."""
|
"""Config flow to handle SENZ OAuth2 authentication."""
|
||||||
|
|
||||||
|
VERSION = 1
|
||||||
|
MINOR_VERSION = 2
|
||||||
DOMAIN = DOMAIN
|
DOMAIN = DOMAIN
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -23,3 +30,37 @@ class OAuth2FlowHandler(
|
|||||||
def extra_authorize_data(self) -> dict:
|
def extra_authorize_data(self) -> dict:
|
||||||
"""Extra data that needs to be appended to the authorize url."""
|
"""Extra data that needs to be appended to the authorize url."""
|
||||||
return {"scope": "restapi offline_access"}
|
return {"scope": "restapi offline_access"}
|
||||||
|
|
||||||
|
async def async_step_reauth(
|
||||||
|
self, entry_data: Mapping[str, Any]
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Perform reauth upon an API authentication error."""
|
||||||
|
|
||||||
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
|
async def async_step_reauth_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Dialog that informs the user that reauth is required."""
|
||||||
|
if user_input is None:
|
||||||
|
return self.async_show_form(step_id="reauth_confirm")
|
||||||
|
|
||||||
|
return await self.async_step_user()
|
||||||
|
|
||||||
|
async def async_oauth_create_entry(self, data: dict) -> ConfigFlowResult:
|
||||||
|
"""Create or update the config entry."""
|
||||||
|
|
||||||
|
token = jwt.decode(
|
||||||
|
data["token"]["access_token"], options={"verify_signature": False}
|
||||||
|
)
|
||||||
|
uid = token["sub"]
|
||||||
|
await self.async_set_unique_id(uid)
|
||||||
|
|
||||||
|
if self.source == SOURCE_REAUTH:
|
||||||
|
self._abort_if_unique_id_mismatch(reason="account_mismatch")
|
||||||
|
return self.async_update_reload_and_abort(
|
||||||
|
self._get_reauth_entry(), data=data
|
||||||
|
)
|
||||||
|
|
||||||
|
self._abort_if_unique_id_configured()
|
||||||
|
return await super().async_oauth_create_entry(data)
|
||||||
|
|||||||
@@ -3,10 +3,9 @@
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from homeassistant.components.diagnostics import async_redact_data
|
from homeassistant.components.diagnostics import async_redact_data
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from .const import DOMAIN
|
from . import SENZConfigEntry
|
||||||
|
|
||||||
TO_REDACT = [
|
TO_REDACT = [
|
||||||
"access_token",
|
"access_token",
|
||||||
@@ -15,13 +14,11 @@ TO_REDACT = [
|
|||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: SENZConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
|
|
||||||
raw_data = (
|
raw_data = ([device.raw_data for device in entry.runtime_data.data.values()],)
|
||||||
[device.raw_data for device in hass.data[DOMAIN][entry.entry_id].data.values()],
|
|
||||||
)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"entry_data": async_redact_data(entry.data, TO_REDACT),
|
"entry_data": async_redact_data(entry.data, TO_REDACT),
|
||||||
|
|||||||
@@ -13,14 +13,13 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
|
||||||
from homeassistant.const import UnitOfTemperature
|
from homeassistant.const import UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from . import SENZDataUpdateCoordinator
|
from . import SENZConfigEntry, SENZDataUpdateCoordinator
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
@@ -45,11 +44,11 @@ SENSORS: tuple[SenzSensorDescription, ...] = (
|
|||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: SENZConfigEntry,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the SENZ sensor entities from a config entry."""
|
"""Set up the SENZ sensor entities from a config entry."""
|
||||||
coordinator: SENZDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = entry.runtime_data
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
SENZSensor(thermostat, coordinator, description)
|
SENZSensor(thermostat, coordinator, description)
|
||||||
for description in SENSORS
|
for description in SENSORS
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
|
"account_mismatch": "The used account does not match the original account",
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
|
"already_configured": "[%key:common::config_flow::abort::already_configured_account%]",
|
||||||
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]",
|
"already_in_progress": "[%key:common::config_flow::abort::already_in_progress%]",
|
||||||
"authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]",
|
"authorize_url_timeout": "[%key:common::config_flow::abort::oauth2_authorize_url_timeout%]",
|
||||||
@@ -9,7 +10,8 @@
|
|||||||
"oauth_error": "[%key:common::config_flow::abort::oauth2_error%]",
|
"oauth_error": "[%key:common::config_flow::abort::oauth2_error%]",
|
||||||
"oauth_failed": "[%key:common::config_flow::abort::oauth2_failed%]",
|
"oauth_failed": "[%key:common::config_flow::abort::oauth2_failed%]",
|
||||||
"oauth_timeout": "[%key:common::config_flow::abort::oauth2_timeout%]",
|
"oauth_timeout": "[%key:common::config_flow::abort::oauth2_timeout%]",
|
||||||
"oauth_unauthorized": "[%key:common::config_flow::abort::oauth2_unauthorized%]"
|
"oauth_unauthorized": "[%key:common::config_flow::abort::oauth2_unauthorized%]",
|
||||||
|
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
|
||||||
},
|
},
|
||||||
"create_entry": {
|
"create_entry": {
|
||||||
"default": "[%key:common::config_flow::create_entry::authenticated%]"
|
"default": "[%key:common::config_flow::create_entry::authenticated%]"
|
||||||
@@ -23,10 +25,20 @@
|
|||||||
"implementation": "[%key:common::config_flow::description::implementation%]"
|
"implementation": "[%key:common::config_flow::description::implementation%]"
|
||||||
},
|
},
|
||||||
"title": "[%key:common::config_flow::title::oauth2_pick_implementation%]"
|
"title": "[%key:common::config_flow::title::oauth2_pick_implementation%]"
|
||||||
|
},
|
||||||
|
"reauth_confirm": {
|
||||||
|
"description": "The SENZ integration needs to re-authenticate your account",
|
||||||
|
"title": "[%key:common::config_flow::title::reauth%]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
|
"config_entry_auth_failed": {
|
||||||
|
"message": "Authentication failed. Please log in again."
|
||||||
|
},
|
||||||
|
"config_entry_not_ready": {
|
||||||
|
"message": "Error while loading the integration."
|
||||||
|
},
|
||||||
"oauth2_implementation_unavailable": {
|
"oauth2_implementation_unavailable": {
|
||||||
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,5 +30,5 @@
|
|||||||
"iot_class": "cloud_push",
|
"iot_class": "cloud_push",
|
||||||
"loggers": ["pysmartthings"],
|
"loggers": ["pysmartthings"],
|
||||||
"quality_scale": "bronze",
|
"quality_scale": "bronze",
|
||||||
"requirements": ["pysmartthings==3.3.2"]
|
"requirements": ["pysmartthings==3.3.3"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -663,7 +663,7 @@
|
|||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
"oauth2_implementation_unavailable": {
|
"oauth2_implementation_unavailable": {
|
||||||
"message": "OAuth2 implementation unavailable, will retry"
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"issues": {
|
"issues": {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
"oauth2_implementation_unavailable": {
|
"oauth2_implementation_unavailable": {
|
||||||
"message": "OAuth2 implementation unavailable, will retry"
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"system_health": {
|
"system_health": {
|
||||||
|
|||||||
@@ -219,7 +219,6 @@ class AbstractTemplateAlarmControlPanel(
|
|||||||
self._attr_code_arm_required: bool = config[CONF_CODE_ARM_REQUIRED]
|
self._attr_code_arm_required: bool = config[CONF_CODE_ARM_REQUIRED]
|
||||||
self._attr_code_format = config[CONF_CODE_FORMAT].value
|
self._attr_code_format = config[CONF_CODE_FORMAT].value
|
||||||
|
|
||||||
self._state: AlarmControlPanelState | None = None
|
|
||||||
self._attr_supported_features: AlarmControlPanelEntityFeature = (
|
self._attr_supported_features: AlarmControlPanelEntityFeature = (
|
||||||
AlarmControlPanelEntityFeature(0)
|
AlarmControlPanelEntityFeature(0)
|
||||||
)
|
)
|
||||||
@@ -244,11 +243,6 @@ class AbstractTemplateAlarmControlPanel(
|
|||||||
if (action_config := config.get(action_id)) is not None:
|
if (action_config := config.get(action_id)) is not None:
|
||||||
yield (action_id, action_config, supported_feature)
|
yield (action_id, action_config, supported_feature)
|
||||||
|
|
||||||
@property
|
|
||||||
def alarm_state(self) -> AlarmControlPanelState | None:
|
|
||||||
"""Return the state of the device."""
|
|
||||||
return self._state
|
|
||||||
|
|
||||||
async def _async_handle_restored_state(self) -> None:
|
async def _async_handle_restored_state(self) -> None:
|
||||||
if (
|
if (
|
||||||
(last_state := await self.async_get_last_state()) is not None
|
(last_state := await self.async_get_last_state()) is not None
|
||||||
@@ -256,14 +250,14 @@ class AbstractTemplateAlarmControlPanel(
|
|||||||
and last_state.state in _VALID_STATES
|
and last_state.state in _VALID_STATES
|
||||||
# The trigger might have fired already while we waited for stored data,
|
# The trigger might have fired already while we waited for stored data,
|
||||||
# then we should not restore state
|
# then we should not restore state
|
||||||
and self._state is None
|
and self._attr_alarm_state is None
|
||||||
):
|
):
|
||||||
self._state = AlarmControlPanelState(last_state.state)
|
self._attr_alarm_state = AlarmControlPanelState(last_state.state)
|
||||||
|
|
||||||
def _handle_state(self, result: Any) -> None:
|
def _handle_state(self, result: Any) -> None:
|
||||||
# Validate state
|
# Validate state
|
||||||
if result in _VALID_STATES:
|
if result in _VALID_STATES:
|
||||||
self._state = result
|
self._attr_alarm_state = result
|
||||||
_LOGGER.debug("Valid state - %s", result)
|
_LOGGER.debug("Valid state - %s", result)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -273,7 +267,7 @@ class AbstractTemplateAlarmControlPanel(
|
|||||||
self.entity_id,
|
self.entity_id,
|
||||||
", ".join(_VALID_STATES),
|
", ".join(_VALID_STATES),
|
||||||
)
|
)
|
||||||
self._state = None
|
self._attr_alarm_state = None
|
||||||
|
|
||||||
async def _async_alarm_arm(self, state: Any, script: Script | None, code: Any):
|
async def _async_alarm_arm(self, state: Any, script: Script | None, code: Any):
|
||||||
"""Arm the panel to specified state with supplied script."""
|
"""Arm the panel to specified state with supplied script."""
|
||||||
@@ -284,7 +278,7 @@ class AbstractTemplateAlarmControlPanel(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if self._attr_assumed_state:
|
if self._attr_assumed_state:
|
||||||
self._state = state
|
self._attr_alarm_state = state
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
async def async_alarm_arm_away(self, code: str | None = None) -> None:
|
async def async_alarm_arm_away(self, code: str | None = None) -> None:
|
||||||
@@ -376,7 +370,7 @@ class StateAlarmControlPanelEntity(TemplateEntity, AbstractTemplateAlarmControlP
|
|||||||
@callback
|
@callback
|
||||||
def _update_state(self, result):
|
def _update_state(self, result):
|
||||||
if isinstance(result, TemplateError):
|
if isinstance(result, TemplateError):
|
||||||
self._state = None
|
self._attr_alarm_state = None
|
||||||
return
|
return
|
||||||
|
|
||||||
self._handle_state(result)
|
self._handle_state(result)
|
||||||
@@ -386,7 +380,7 @@ class StateAlarmControlPanelEntity(TemplateEntity, AbstractTemplateAlarmControlP
|
|||||||
"""Set up templates."""
|
"""Set up templates."""
|
||||||
if self._template:
|
if self._template:
|
||||||
self.add_template_attribute(
|
self.add_template_attribute(
|
||||||
"_state", self._template, None, self._update_state
|
"_attr_alarm_state", self._template, None, self._update_state
|
||||||
)
|
)
|
||||||
super()._async_setup_templates()
|
super()._async_setup_templates()
|
||||||
|
|
||||||
|
|||||||
@@ -20,5 +20,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/tesla_wall_connector",
|
"documentation": "https://www.home-assistant.io/integrations/tesla_wall_connector",
|
||||||
"iot_class": "local_polling",
|
"iot_class": "local_polling",
|
||||||
"loggers": ["tesla_wall_connector"],
|
"loggers": ["tesla_wall_connector"],
|
||||||
"requirements": ["tesla-wall-connector==1.0.2"]
|
"requirements": ["tesla-wall-connector==1.1.0"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ class TeslemetryStreamingUpdateEntity(
|
|||||||
if self._download_percentage > 1 and self._download_percentage < 100:
|
if self._download_percentage > 1 and self._download_percentage < 100:
|
||||||
self._attr_in_progress = True
|
self._attr_in_progress = True
|
||||||
self._attr_update_percentage = self._download_percentage
|
self._attr_update_percentage = self._download_percentage
|
||||||
elif self._install_percentage > 1:
|
elif self._install_percentage > 10:
|
||||||
self._attr_in_progress = True
|
self._attr_in_progress = True
|
||||||
self._attr_update_percentage = self._install_percentage
|
self._attr_update_percentage = self._install_percentage
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,33 +1,83 @@
|
|||||||
"""Support for Tibber."""
|
"""Support for Tibber."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
from aiohttp.client_exceptions import ClientError, ClientResponseError
|
||||||
import tibber
|
import tibber
|
||||||
|
from tibber import data_api as tibber_data_api
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN, EVENT_HOMEASSISTANT_STOP, Platform
|
from homeassistant.const import CONF_ACCESS_TOKEN, EVENT_HOMEASSISTANT_STOP, Platform
|
||||||
from homeassistant.core import Event, HomeAssistant
|
from homeassistant.core import Event, HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||||
|
ImplementationUnavailableError,
|
||||||
|
OAuth2Session,
|
||||||
|
async_get_config_entry_implementation,
|
||||||
|
)
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util import dt as dt_util, ssl as ssl_util
|
from homeassistant.util import dt as dt_util, ssl as ssl_util
|
||||||
|
|
||||||
from .const import DATA_HASS_CONFIG, DOMAIN
|
from .const import (
|
||||||
|
API_TYPE_DATA_API,
|
||||||
|
API_TYPE_GRAPHQL,
|
||||||
|
CONF_API_TYPE,
|
||||||
|
DATA_HASS_CONFIG,
|
||||||
|
DOMAIN,
|
||||||
|
)
|
||||||
from .services import async_setup_services
|
from .services import async_setup_services
|
||||||
|
|
||||||
PLATFORMS = [Platform.NOTIFY, Platform.SENSOR]
|
GRAPHQL_PLATFORMS = [Platform.NOTIFY, Platform.SENSOR]
|
||||||
|
DATA_API_PLATFORMS = [Platform.SENSOR]
|
||||||
|
|
||||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(slots=True)
|
||||||
|
class TibberGraphQLRuntimeData:
|
||||||
|
"""Runtime data for GraphQL-based Tibber entries."""
|
||||||
|
|
||||||
|
tibber: tibber.Tibber
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(slots=True)
|
||||||
|
class TibberDataAPIRuntimeData:
|
||||||
|
"""Runtime data for Tibber Data API entries."""
|
||||||
|
|
||||||
|
session: OAuth2Session
|
||||||
|
_client: tibber_data_api.TibberDataAPI | None = None
|
||||||
|
|
||||||
|
async def async_get_client(
|
||||||
|
self, hass: HomeAssistant
|
||||||
|
) -> tibber_data_api.TibberDataAPI:
|
||||||
|
"""Return an authenticated Tibber Data API client."""
|
||||||
|
await self.session.async_ensure_token_valid()
|
||||||
|
token = self.session.token
|
||||||
|
access_token = token.get(CONF_ACCESS_TOKEN)
|
||||||
|
if not access_token:
|
||||||
|
raise ConfigEntryAuthFailed("Access token missing from OAuth session")
|
||||||
|
if self._client is None:
|
||||||
|
self._client = tibber_data_api.TibberDataAPI(
|
||||||
|
access_token,
|
||||||
|
websession=async_get_clientsession(hass),
|
||||||
|
)
|
||||||
|
self._client.set_access_token(access_token)
|
||||||
|
return self._client
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Tibber component."""
|
"""Set up the Tibber component."""
|
||||||
|
|
||||||
hass.data[DATA_HASS_CONFIG] = config
|
hass.data[DATA_HASS_CONFIG] = config
|
||||||
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
|
||||||
async_setup_services(hass)
|
async_setup_services(hass)
|
||||||
|
|
||||||
@@ -37,45 +87,100 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up a config entry."""
|
"""Set up a config entry."""
|
||||||
|
|
||||||
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
api_type = entry.data.get(CONF_API_TYPE, API_TYPE_GRAPHQL)
|
||||||
|
|
||||||
|
if api_type == API_TYPE_DATA_API:
|
||||||
|
return await _async_setup_data_api_entry(hass, entry)
|
||||||
|
|
||||||
|
return await _async_setup_graphql_entry(hass, entry)
|
||||||
|
|
||||||
|
|
||||||
|
async def _async_setup_graphql_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
"""Set up the legacy GraphQL Tibber entry."""
|
||||||
|
|
||||||
tibber_connection = tibber.Tibber(
|
tibber_connection = tibber.Tibber(
|
||||||
access_token=entry.data[CONF_ACCESS_TOKEN],
|
access_token=entry.data[CONF_ACCESS_TOKEN],
|
||||||
websession=async_get_clientsession(hass),
|
websession=async_get_clientsession(hass),
|
||||||
time_zone=dt_util.get_default_time_zone(),
|
time_zone=dt_util.get_default_time_zone(),
|
||||||
ssl=ssl_util.get_default_context(),
|
ssl=ssl_util.get_default_context(),
|
||||||
)
|
)
|
||||||
hass.data[DOMAIN] = tibber_connection
|
|
||||||
|
|
||||||
async def _close(event: Event) -> None:
|
runtime = TibberGraphQLRuntimeData(tibber_connection)
|
||||||
|
entry.runtime_data = runtime
|
||||||
|
hass.data[DOMAIN][API_TYPE_GRAPHQL] = runtime
|
||||||
|
|
||||||
|
async def _close(_event: Event) -> None:
|
||||||
await tibber_connection.rt_disconnect()
|
await tibber_connection.rt_disconnect()
|
||||||
|
|
||||||
entry.async_on_unload(hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _close))
|
entry.async_on_unload(hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _close))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await tibber_connection.update_info()
|
await tibber_connection.update_info()
|
||||||
|
|
||||||
except (
|
except (
|
||||||
TimeoutError,
|
TimeoutError,
|
||||||
aiohttp.ClientError,
|
aiohttp.ClientError,
|
||||||
tibber.RetryableHttpExceptionError,
|
tibber.RetryableHttpExceptionError,
|
||||||
) as err:
|
) as err:
|
||||||
raise ConfigEntryNotReady("Unable to connect") from err
|
raise ConfigEntryNotReady("Unable to connect") from err
|
||||||
except tibber.InvalidLoginError as exp:
|
except tibber.InvalidLoginError as err:
|
||||||
_LOGGER.error("Failed to login. %s", exp)
|
_LOGGER.error("Failed to login to Tibber GraphQL API: %s", err)
|
||||||
return False
|
return False
|
||||||
except tibber.FatalHttpExceptionError:
|
except tibber.FatalHttpExceptionError as err:
|
||||||
|
_LOGGER.error("Fatal error communicating with Tibber GraphQL API: %s", err)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, GRAPHQL_PLATFORMS)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def _async_setup_data_api_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
"""Set up a Tibber Data API entry."""
|
||||||
|
|
||||||
|
try:
|
||||||
|
implementation = await async_get_config_entry_implementation(hass, entry)
|
||||||
|
except ImplementationUnavailableError as err:
|
||||||
|
raise ConfigEntryNotReady(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="oauth2_implementation_unavailable",
|
||||||
|
) from err
|
||||||
|
|
||||||
|
session = OAuth2Session(hass, entry, implementation)
|
||||||
|
|
||||||
|
try:
|
||||||
|
await session.async_ensure_token_valid()
|
||||||
|
except ClientResponseError as err:
|
||||||
|
if 400 <= err.status < 500:
|
||||||
|
raise ConfigEntryAuthFailed(
|
||||||
|
"OAuth session is not valid, reauthentication required"
|
||||||
|
) from err
|
||||||
|
raise ConfigEntryNotReady from err
|
||||||
|
except ClientError as err:
|
||||||
|
raise ConfigEntryNotReady from err
|
||||||
|
|
||||||
|
runtime = TibberDataAPIRuntimeData(session=session)
|
||||||
|
entry.runtime_data = runtime
|
||||||
|
hass.data[DOMAIN][API_TYPE_DATA_API] = runtime
|
||||||
|
|
||||||
|
await hass.config_entries.async_forward_entry_setups(entry, DATA_API_PLATFORMS)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
|
api_type = config_entry.data.get(CONF_API_TYPE, API_TYPE_GRAPHQL)
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
config_entry, PLATFORMS
|
config_entry,
|
||||||
|
GRAPHQL_PLATFORMS if api_type == API_TYPE_GRAPHQL else DATA_API_PLATFORMS,
|
||||||
)
|
)
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
tibber_connection = hass.data[DOMAIN]
|
if api_type == API_TYPE_GRAPHQL:
|
||||||
await tibber_connection.rt_disconnect()
|
runtime = hass.data[DOMAIN].get(api_type)
|
||||||
|
if runtime:
|
||||||
|
tibber_connection = runtime.tibber
|
||||||
|
await tibber_connection.rt_disconnect()
|
||||||
|
|
||||||
|
hass.data[DOMAIN].pop(api_type, None)
|
||||||
return unload_ok
|
return unload_ok
|
||||||
|
|||||||
15
homeassistant/components/tibber/application_credentials.py
Normal file
15
homeassistant/components/tibber/application_credentials.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
"""Application credentials platform for Tibber."""
|
||||||
|
|
||||||
|
from homeassistant.components.application_credentials import AuthorizationServer
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
AUTHORIZE_URL = "https://thewall.tibber.com/connect/authorize"
|
||||||
|
TOKEN_URL = "https://thewall.tibber.com/connect/token"
|
||||||
|
|
||||||
|
|
||||||
|
async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer:
|
||||||
|
"""Return authorization server for Tibber Data API."""
|
||||||
|
return AuthorizationServer(
|
||||||
|
authorize_url=AUTHORIZE_URL,
|
||||||
|
token_url=TOKEN_URL,
|
||||||
|
)
|
||||||
@@ -2,36 +2,117 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Mapping
|
||||||
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import tibber
|
import tibber
|
||||||
|
from tibber.data_api import TibberDataAPI
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigFlowResult
|
||||||
from homeassistant.const import CONF_ACCESS_TOKEN
|
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_TOKEN
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
|
from homeassistant.helpers.config_entry_oauth2_flow import (
|
||||||
|
AbstractOAuth2FlowHandler,
|
||||||
|
async_get_config_entry_implementation,
|
||||||
|
async_get_implementations,
|
||||||
|
)
|
||||||
|
from homeassistant.helpers.selector import SelectSelector, SelectSelectorConfig
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import (
|
||||||
|
API_TYPE_DATA_API,
|
||||||
|
API_TYPE_GRAPHQL,
|
||||||
|
CONF_API_TYPE,
|
||||||
|
DATA_API_DEFAULT_SCOPES,
|
||||||
|
DOMAIN,
|
||||||
|
)
|
||||||
|
|
||||||
|
TYPE_SELECTOR = vol.Schema(
|
||||||
|
{
|
||||||
|
vol.Required(CONF_API_TYPE, default=API_TYPE_GRAPHQL): SelectSelector(
|
||||||
|
SelectSelectorConfig(
|
||||||
|
options=[API_TYPE_GRAPHQL, API_TYPE_DATA_API],
|
||||||
|
translation_key="api_type",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
GRAPHQL_SCHEMA = vol.Schema({vol.Required(CONF_ACCESS_TOKEN): str})
|
||||||
|
|
||||||
DATA_SCHEMA = vol.Schema({vol.Required(CONF_ACCESS_TOKEN): str})
|
|
||||||
ERR_TIMEOUT = "timeout"
|
ERR_TIMEOUT = "timeout"
|
||||||
ERR_CLIENT = "cannot_connect"
|
ERR_CLIENT = "cannot_connect"
|
||||||
ERR_TOKEN = "invalid_access_token"
|
ERR_TOKEN = "invalid_access_token"
|
||||||
TOKEN_URL = "https://developer.tibber.com/settings/access-token"
|
TOKEN_URL = "https://developer.tibber.com/settings/access-token"
|
||||||
|
DATA_API_DOC_URL = "https://data-api.tibber.com/docs/auth/"
|
||||||
|
APPLICATION_CREDENTIALS_DOC_URL = (
|
||||||
|
"https://www.home-assistant.io/integrations/application_credentials/"
|
||||||
|
)
|
||||||
|
|
||||||
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class TibberConfigFlow(ConfigFlow, domain=DOMAIN):
|
class TibberConfigFlow(AbstractOAuth2FlowHandler, domain=DOMAIN):
|
||||||
"""Handle a config flow for Tibber integration."""
|
"""Handle a config flow for Tibber integration."""
|
||||||
|
|
||||||
|
DOMAIN = DOMAIN
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
MINOR_VERSION = 1
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
"""Initialize the config flow."""
|
||||||
|
super().__init__()
|
||||||
|
self._api_type: str | None = None
|
||||||
|
self._data_api_home_ids: list[str] = []
|
||||||
|
self._data_api_user_sub: str | None = None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def logger(self) -> logging.Logger:
|
||||||
|
"""Return the logger."""
|
||||||
|
return _LOGGER
|
||||||
|
|
||||||
|
@property
|
||||||
|
def extra_authorize_data(self) -> dict:
|
||||||
|
"""Extra data appended to the authorize URL."""
|
||||||
|
if self._api_type != API_TYPE_DATA_API:
|
||||||
|
return super().extra_authorize_data
|
||||||
|
return {
|
||||||
|
**super().extra_authorize_data,
|
||||||
|
"scope": " ".join(DATA_API_DEFAULT_SCOPES),
|
||||||
|
}
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle the initial step."""
|
"""Handle the initial step."""
|
||||||
|
|
||||||
self._async_abort_entries_match()
|
if user_input is None:
|
||||||
|
return self.async_show_form(
|
||||||
|
step_id="user",
|
||||||
|
data_schema=TYPE_SELECTOR,
|
||||||
|
description_placeholders={"url": DATA_API_DOC_URL},
|
||||||
|
)
|
||||||
|
|
||||||
|
self._api_type = user_input[CONF_API_TYPE]
|
||||||
|
|
||||||
|
if self._api_type == API_TYPE_GRAPHQL:
|
||||||
|
return await self.async_step_graphql()
|
||||||
|
|
||||||
|
return await self.async_step_data_api()
|
||||||
|
|
||||||
|
async def async_step_graphql(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle GraphQL token based configuration."""
|
||||||
|
|
||||||
|
if self.source != SOURCE_REAUTH:
|
||||||
|
for entry in self._async_current_entries(include_ignore=False):
|
||||||
|
if entry.entry_id == self.context.get("entry_id"):
|
||||||
|
continue
|
||||||
|
if entry.data.get(CONF_API_TYPE, API_TYPE_GRAPHQL) == API_TYPE_GRAPHQL:
|
||||||
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
access_token = user_input[CONF_ACCESS_TOKEN].replace(" ", "")
|
access_token = user_input[CONF_ACCESS_TOKEN].replace(" ", "")
|
||||||
@@ -58,24 +139,145 @@ class TibberConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="graphql",
|
||||||
data_schema=DATA_SCHEMA,
|
data_schema=GRAPHQL_SCHEMA,
|
||||||
description_placeholders={"url": TOKEN_URL},
|
description_placeholders={"url": TOKEN_URL},
|
||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
unique_id = tibber_connection.user_id
|
unique_id = tibber_connection.user_id
|
||||||
await self.async_set_unique_id(unique_id)
|
await self.async_set_unique_id(unique_id)
|
||||||
|
|
||||||
|
if self.source == SOURCE_REAUTH:
|
||||||
|
self._abort_if_unique_id_mismatch(reason="wrong_account")
|
||||||
|
return self.async_update_reload_and_abort(
|
||||||
|
self._get_reauth_entry(),
|
||||||
|
data_updates={
|
||||||
|
CONF_API_TYPE: API_TYPE_GRAPHQL,
|
||||||
|
CONF_ACCESS_TOKEN: access_token,
|
||||||
|
},
|
||||||
|
title=tibber_connection.name,
|
||||||
|
)
|
||||||
|
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
|
data = {
|
||||||
|
CONF_API_TYPE: API_TYPE_GRAPHQL,
|
||||||
|
CONF_ACCESS_TOKEN: access_token,
|
||||||
|
}
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=tibber_connection.name,
|
title=tibber_connection.name,
|
||||||
data={CONF_ACCESS_TOKEN: access_token},
|
data=data,
|
||||||
)
|
)
|
||||||
|
|
||||||
return self.async_show_form(
|
return self.async_show_form(
|
||||||
step_id="user",
|
step_id="graphql",
|
||||||
data_schema=DATA_SCHEMA,
|
data_schema=GRAPHQL_SCHEMA,
|
||||||
description_placeholders={"url": TOKEN_URL},
|
description_placeholders={"url": TOKEN_URL},
|
||||||
errors={},
|
errors={},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def async_step_data_api(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle the Data API OAuth configuration."""
|
||||||
|
|
||||||
|
implementations = await async_get_implementations(self.hass, self.DOMAIN)
|
||||||
|
if not implementations:
|
||||||
|
return self.async_abort(
|
||||||
|
reason="missing_credentials",
|
||||||
|
description_placeholders={
|
||||||
|
"application_credentials_url": APPLICATION_CREDENTIALS_DOC_URL,
|
||||||
|
"data_api_url": DATA_API_DOC_URL,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.source != SOURCE_REAUTH:
|
||||||
|
for entry in self._async_current_entries(include_ignore=False):
|
||||||
|
if entry.entry_id == self.context.get("entry_id"):
|
||||||
|
continue
|
||||||
|
if entry.data.get(CONF_API_TYPE, API_TYPE_GRAPHQL) == API_TYPE_DATA_API:
|
||||||
|
return self.async_abort(reason="already_configured")
|
||||||
|
|
||||||
|
return await self.async_step_pick_implementation(user_input)
|
||||||
|
|
||||||
|
async def async_oauth_create_entry(self, data: dict) -> ConfigFlowResult:
|
||||||
|
"""Finalize the OAuth flow and create the config entry."""
|
||||||
|
|
||||||
|
assert self._api_type == API_TYPE_DATA_API
|
||||||
|
|
||||||
|
token: dict[str, Any] = data["token"]
|
||||||
|
|
||||||
|
client = TibberDataAPI(
|
||||||
|
token[CONF_ACCESS_TOKEN],
|
||||||
|
websession=async_get_clientsession(self.hass),
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
userinfo = await client.get_userinfo()
|
||||||
|
except (
|
||||||
|
tibber.InvalidLoginError,
|
||||||
|
tibber.FatalHttpExceptionError,
|
||||||
|
) as err:
|
||||||
|
self.logger.error("Authentication failed against Data API: %s", err)
|
||||||
|
return self.async_abort(reason="oauth_invalid_token")
|
||||||
|
except (aiohttp.ClientError, TimeoutError) as err:
|
||||||
|
self.logger.error("Error retrieving homes via Data API: %s", err)
|
||||||
|
return self.async_abort(reason="cannot_connect")
|
||||||
|
|
||||||
|
unique_id = userinfo["email"]
|
||||||
|
title = userinfo["email"]
|
||||||
|
await self.async_set_unique_id(unique_id)
|
||||||
|
if self.source == SOURCE_REAUTH:
|
||||||
|
reauth_entry = self._get_reauth_entry()
|
||||||
|
self._abort_if_unique_id_mismatch(
|
||||||
|
reason="wrong_account",
|
||||||
|
description_placeholders={"email": reauth_entry.unique_id or ""},
|
||||||
|
)
|
||||||
|
return self.async_update_reload_and_abort(
|
||||||
|
reauth_entry,
|
||||||
|
data_updates={
|
||||||
|
CONF_API_TYPE: API_TYPE_DATA_API,
|
||||||
|
"auth_implementation": data["auth_implementation"],
|
||||||
|
CONF_TOKEN: token,
|
||||||
|
},
|
||||||
|
title=title,
|
||||||
|
)
|
||||||
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
|
entry_data: dict[str, Any] = {
|
||||||
|
CONF_API_TYPE: API_TYPE_DATA_API,
|
||||||
|
"auth_implementation": data["auth_implementation"],
|
||||||
|
CONF_TOKEN: token,
|
||||||
|
}
|
||||||
|
return self.async_create_entry(
|
||||||
|
title=title,
|
||||||
|
data=entry_data,
|
||||||
|
)
|
||||||
|
|
||||||
|
async def async_step_reauth(
|
||||||
|
self, entry_data: Mapping[str, Any]
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Handle reauthentication."""
|
||||||
|
|
||||||
|
api_type = entry_data.get(CONF_API_TYPE, API_TYPE_GRAPHQL)
|
||||||
|
self._api_type = api_type
|
||||||
|
|
||||||
|
if api_type == API_TYPE_DATA_API:
|
||||||
|
self.flow_impl = await async_get_config_entry_implementation(
|
||||||
|
self.hass, self._get_reauth_entry()
|
||||||
|
)
|
||||||
|
return await self.async_step_auth()
|
||||||
|
|
||||||
|
self.context["title_placeholders"] = {"name": self._get_reauth_entry().title}
|
||||||
|
return await self.async_step_reauth_confirm()
|
||||||
|
|
||||||
|
async def async_step_reauth_confirm(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
|
"""Confirm the reauth dialog for GraphQL entries."""
|
||||||
|
if user_input is None:
|
||||||
|
return self.async_show_form(step_id="reauth_confirm")
|
||||||
|
|
||||||
|
return await self.async_step_graphql()
|
||||||
|
|||||||
@@ -3,3 +3,19 @@
|
|||||||
DATA_HASS_CONFIG = "tibber_hass_config"
|
DATA_HASS_CONFIG = "tibber_hass_config"
|
||||||
DOMAIN = "tibber"
|
DOMAIN = "tibber"
|
||||||
MANUFACTURER = "Tibber"
|
MANUFACTURER = "Tibber"
|
||||||
|
CONF_API_TYPE = "api_type"
|
||||||
|
API_TYPE_GRAPHQL = "graphql"
|
||||||
|
API_TYPE_DATA_API = "data_api"
|
||||||
|
DATA_API_DEFAULT_SCOPES = [
|
||||||
|
"openid",
|
||||||
|
"profile",
|
||||||
|
"email",
|
||||||
|
"offline_access",
|
||||||
|
"data-api-user-read",
|
||||||
|
"data-api-chargers-read",
|
||||||
|
"data-api-energy-systems-read",
|
||||||
|
"data-api-homes-read",
|
||||||
|
"data-api-thermostats-read",
|
||||||
|
"data-api-vehicles-read",
|
||||||
|
"data-api-inverters-read",
|
||||||
|
]
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import cast
|
from typing import Any, cast
|
||||||
|
|
||||||
import tibber
|
import tibber
|
||||||
|
from tibber.data_api import TibberDataAPI, TibberDevice
|
||||||
|
|
||||||
from homeassistant.components.recorder import get_instance
|
from homeassistant.components.recorder import get_instance
|
||||||
from homeassistant.components.recorder.models import (
|
from homeassistant.components.recorder.models import (
|
||||||
@@ -22,6 +23,7 @@ from homeassistant.components.recorder.statistics import (
|
|||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import UnitOfEnergy
|
from homeassistant.const import UnitOfEnergy
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
from homeassistant.util.unit_conversion import EnergyConverter
|
from homeassistant.util.unit_conversion import EnergyConverter
|
||||||
@@ -187,3 +189,50 @@ class TibberDataCoordinator(DataUpdateCoordinator[None]):
|
|||||||
unit_of_measurement=unit,
|
unit_of_measurement=unit,
|
||||||
)
|
)
|
||||||
async_add_external_statistics(self.hass, metadata, statistics)
|
async_add_external_statistics(self.hass, metadata, statistics)
|
||||||
|
|
||||||
|
|
||||||
|
class TibberDataAPICoordinator(DataUpdateCoordinator[dict[str, TibberDevice]]):
|
||||||
|
"""Fetch and cache Tibber Data API device capabilities."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
runtime_data: Any,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the coordinator."""
|
||||||
|
super().__init__(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
name=f"{DOMAIN} Data API",
|
||||||
|
update_interval=timedelta(minutes=10),
|
||||||
|
config_entry=entry,
|
||||||
|
)
|
||||||
|
self._runtime_data = runtime_data
|
||||||
|
|
||||||
|
async def _async_setup(self) -> None:
|
||||||
|
"""Setup the coordinator."""
|
||||||
|
try:
|
||||||
|
client: TibberDataAPI = await self._runtime_data.async_get_client(self.hass)
|
||||||
|
except ConfigEntryAuthFailed:
|
||||||
|
raise
|
||||||
|
except Exception as err:
|
||||||
|
raise UpdateFailed(
|
||||||
|
f"Unable to create Tibber Data API client: {err}"
|
||||||
|
) from err
|
||||||
|
|
||||||
|
self.data = await client.get_all_devices()
|
||||||
|
|
||||||
|
async def _async_update_data(self) -> dict[str, TibberDevice]:
|
||||||
|
"""Fetch the latest device capabilities from the Tibber Data API."""
|
||||||
|
try:
|
||||||
|
client: TibberDataAPI = await self._runtime_data.async_get_client(self.hass)
|
||||||
|
except ConfigEntryAuthFailed:
|
||||||
|
raise
|
||||||
|
except Exception as err:
|
||||||
|
raise UpdateFailed(
|
||||||
|
f"Unable to create Tibber Data API client: {err}"
|
||||||
|
) from err
|
||||||
|
|
||||||
|
devices: dict[str, TibberDevice] = await client.update_devices()
|
||||||
|
return devices
|
||||||
|
|||||||
@@ -4,29 +4,78 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
import tibber
|
import tibber
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import API_TYPE_DATA_API, API_TYPE_GRAPHQL, CONF_API_TYPE, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, config_entry: ConfigEntry
|
hass: HomeAssistant, config_entry: ConfigEntry
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Return diagnostics for a config entry."""
|
"""Return diagnostics for a config entry."""
|
||||||
tibber_connection: tibber.Tibber = hass.data[DOMAIN]
|
|
||||||
|
api_type = config_entry.data.get(CONF_API_TYPE, API_TYPE_GRAPHQL)
|
||||||
|
domain_data = hass.data.get(DOMAIN, {})
|
||||||
|
|
||||||
|
if api_type == API_TYPE_GRAPHQL:
|
||||||
|
runtime = domain_data.get(API_TYPE_GRAPHQL, {})
|
||||||
|
if runtime and hasattr(runtime, "tibber"):
|
||||||
|
tibber_connection: tibber.Tibber = runtime.tibber
|
||||||
|
return {
|
||||||
|
"api_type": API_TYPE_GRAPHQL,
|
||||||
|
"homes": [
|
||||||
|
{
|
||||||
|
"last_data_timestamp": home.last_data_timestamp,
|
||||||
|
"has_active_subscription": home.has_active_subscription,
|
||||||
|
"has_real_time_consumption": home.has_real_time_consumption,
|
||||||
|
"last_cons_data_timestamp": home.last_cons_data_timestamp,
|
||||||
|
"country": home.country,
|
||||||
|
}
|
||||||
|
for home in tibber_connection.get_homes(only_active=False)
|
||||||
|
],
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
"api_type": API_TYPE_GRAPHQL,
|
||||||
|
"homes": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime = domain_data.get(API_TYPE_DATA_API)
|
||||||
|
if runtime is None:
|
||||||
|
return {
|
||||||
|
"api_type": API_TYPE_DATA_API,
|
||||||
|
"devices": [],
|
||||||
|
}
|
||||||
|
|
||||||
|
devices: dict[str, Any] = {}
|
||||||
|
error: str | None = None
|
||||||
|
try:
|
||||||
|
devices = await (await runtime.async_get_client(hass)).get_all_devices()
|
||||||
|
except (
|
||||||
|
ConfigEntryAuthFailed,
|
||||||
|
TimeoutError,
|
||||||
|
aiohttp.ClientError,
|
||||||
|
tibber.InvalidLoginError,
|
||||||
|
tibber.RetryableHttpExceptionError,
|
||||||
|
tibber.FatalHttpExceptionError,
|
||||||
|
) as err:
|
||||||
|
devices = {}
|
||||||
|
error = repr(err)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"homes": [
|
"api_type": API_TYPE_DATA_API,
|
||||||
|
"error": error,
|
||||||
|
"devices": [
|
||||||
{
|
{
|
||||||
"last_data_timestamp": home.last_data_timestamp,
|
"id": device.id,
|
||||||
"has_active_subscription": home.has_active_subscription,
|
"name": device.name,
|
||||||
"has_real_time_consumption": home.has_real_time_consumption,
|
"brand": device.brand,
|
||||||
"last_cons_data_timestamp": home.last_cons_data_timestamp,
|
"model": device.model,
|
||||||
"country": home.country,
|
|
||||||
}
|
}
|
||||||
for home in tibber_connection.get_homes(only_active=False)
|
for device in devices.values()
|
||||||
]
|
],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
"name": "Tibber",
|
"name": "Tibber",
|
||||||
"codeowners": ["@danielhiversen"],
|
"codeowners": ["@danielhiversen"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": ["recorder"],
|
"dependencies": ["application_credentials", "recorder"],
|
||||||
"documentation": "https://www.home-assistant.io/integrations/tibber",
|
"documentation": "https://www.home-assistant.io/integrations/tibber",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["tibber"],
|
"loggers": ["tibber"],
|
||||||
"requirements": ["pyTibber==0.32.2"]
|
"requirements": ["pyTibber==0.33.1"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
from . import DOMAIN
|
from .const import API_TYPE_GRAPHQL, DOMAIN
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
@@ -39,7 +39,7 @@ class TibberNotificationEntity(NotifyEntity):
|
|||||||
|
|
||||||
async def async_send_message(self, message: str, title: str | None = None) -> None:
|
async def async_send_message(self, message: str, title: str | None = None) -> None:
|
||||||
"""Send a message to Tibber devices."""
|
"""Send a message to Tibber devices."""
|
||||||
tibber_connection: Tibber = self.hass.data[DOMAIN]
|
tibber_connection: Tibber = self.hass.data[DOMAIN][API_TYPE_GRAPHQL].tibber
|
||||||
try:
|
try:
|
||||||
await tibber_connection.send_notification(
|
await tibber_connection.send_notification(
|
||||||
title or ATTR_TITLE_DEFAULT, message
|
title or ATTR_TITLE_DEFAULT, message
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ from random import randrange
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import tibber
|
from tibber import FatalHttpExceptionError, RetryableHttpExceptionError, TibberHome
|
||||||
|
from tibber.data_api import TibberDevice
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
@@ -27,6 +28,7 @@ from homeassistant.const import (
|
|||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
UnitOfElectricPotential,
|
UnitOfElectricPotential,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
|
UnitOfLength,
|
||||||
UnitOfPower,
|
UnitOfPower,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant, callback
|
from homeassistant.core import Event, HomeAssistant, callback
|
||||||
@@ -41,8 +43,14 @@ from homeassistant.helpers.update_coordinator import (
|
|||||||
)
|
)
|
||||||
from homeassistant.util import Throttle, dt as dt_util
|
from homeassistant.util import Throttle, dt as dt_util
|
||||||
|
|
||||||
from .const import DOMAIN, MANUFACTURER
|
from .const import (
|
||||||
from .coordinator import TibberDataCoordinator
|
API_TYPE_DATA_API,
|
||||||
|
API_TYPE_GRAPHQL,
|
||||||
|
CONF_API_TYPE,
|
||||||
|
DOMAIN,
|
||||||
|
MANUFACTURER,
|
||||||
|
)
|
||||||
|
from .coordinator import TibberDataAPICoordinator, TibberDataCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -260,6 +268,58 @@ SENSORS: tuple[SensorEntityDescription, ...] = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
DATA_API_SENSORS: tuple[SensorEntityDescription, ...] = (
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="storage.stateOfCharge",
|
||||||
|
translation_key="storage_state_of_charge",
|
||||||
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="storage.targetStateOfCharge",
|
||||||
|
translation_key="storage_target_state_of_charge",
|
||||||
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="connector.status",
|
||||||
|
translation_key="connector_status",
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
options=["connected", "disconnected", "unknown"],
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="charging.status",
|
||||||
|
translation_key="charging_status",
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
options=["charging", "idle", "unknown"],
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="range.remaining",
|
||||||
|
translation_key="range_remaining",
|
||||||
|
device_class=SensorDeviceClass.DISTANCE,
|
||||||
|
native_unit_of_measurement=UnitOfLength.KILOMETERS,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
suggested_display_precision=1,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="charging.current.max",
|
||||||
|
translation_key="charging_current_max",
|
||||||
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
SensorEntityDescription(
|
||||||
|
key="charging.current.offlineFallback",
|
||||||
|
translation_key="charging_current_offline_fallback",
|
||||||
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
@@ -267,7 +327,11 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the Tibber sensor."""
|
"""Set up the Tibber sensor."""
|
||||||
|
|
||||||
tibber_connection = hass.data[DOMAIN]
|
if entry.data.get(CONF_API_TYPE, API_TYPE_GRAPHQL) == API_TYPE_DATA_API:
|
||||||
|
await _async_setup_data_api_sensors(hass, entry, async_add_entities)
|
||||||
|
return
|
||||||
|
|
||||||
|
tibber_connection = hass.data[DOMAIN][API_TYPE_GRAPHQL].tibber
|
||||||
|
|
||||||
entity_registry = er.async_get(hass)
|
entity_registry = er.async_get(hass)
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
@@ -280,7 +344,11 @@ async def async_setup_entry(
|
|||||||
except TimeoutError as err:
|
except TimeoutError as err:
|
||||||
_LOGGER.error("Timeout connecting to Tibber home: %s ", err)
|
_LOGGER.error("Timeout connecting to Tibber home: %s ", err)
|
||||||
raise PlatformNotReady from err
|
raise PlatformNotReady from err
|
||||||
except (tibber.RetryableHttpExceptionError, aiohttp.ClientError) as err:
|
except (
|
||||||
|
RetryableHttpExceptionError,
|
||||||
|
FatalHttpExceptionError,
|
||||||
|
aiohttp.ClientError,
|
||||||
|
) as err:
|
||||||
_LOGGER.error("Error connecting to Tibber home: %s ", err)
|
_LOGGER.error("Error connecting to Tibber home: %s ", err)
|
||||||
raise PlatformNotReady from err
|
raise PlatformNotReady from err
|
||||||
|
|
||||||
@@ -328,14 +396,95 @@ async def async_setup_entry(
|
|||||||
async_add_entities(entities, True)
|
async_add_entities(entities, True)
|
||||||
|
|
||||||
|
|
||||||
|
async def _async_setup_data_api_sensors(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entry: ConfigEntry,
|
||||||
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Set up sensors backed by the Tibber Data API."""
|
||||||
|
|
||||||
|
domain_data = hass.data.get(DOMAIN, {})
|
||||||
|
runtime = domain_data[API_TYPE_DATA_API]
|
||||||
|
|
||||||
|
coordinator = TibberDataAPICoordinator(hass, entry, runtime)
|
||||||
|
|
||||||
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
|
entities: list[TibberDataAPISensor] = []
|
||||||
|
api_sensors = {sensor.key: sensor for sensor in DATA_API_SENSORS}
|
||||||
|
|
||||||
|
for device in coordinator.data.values():
|
||||||
|
for sensor in device.sensors:
|
||||||
|
description: SensorEntityDescription | None = api_sensors.get(sensor.id)
|
||||||
|
if description is None:
|
||||||
|
_LOGGER.error("Sensor %s not found", sensor)
|
||||||
|
continue
|
||||||
|
entities.append(
|
||||||
|
TibberDataAPISensor(
|
||||||
|
coordinator, device, description, sensor.description
|
||||||
|
)
|
||||||
|
)
|
||||||
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
|
||||||
|
class TibberDataAPISensor(CoordinatorEntity[TibberDataAPICoordinator], SensorEntity):
|
||||||
|
"""Representation of a Tibber Data API capability sensor."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: TibberDataAPICoordinator,
|
||||||
|
device: TibberDevice,
|
||||||
|
entity_description: SensorEntityDescription,
|
||||||
|
name: str,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize the sensor."""
|
||||||
|
super().__init__(coordinator)
|
||||||
|
|
||||||
|
self._device: TibberDevice = device
|
||||||
|
self.entity_description = entity_description
|
||||||
|
self._attr_name = name
|
||||||
|
|
||||||
|
self._attr_unique_id = f"{device.external_id}_{self.entity_description.key}"
|
||||||
|
|
||||||
|
self._attr_device_info = DeviceInfo(
|
||||||
|
identifiers={(DOMAIN, device.external_id)},
|
||||||
|
name=device.name,
|
||||||
|
manufacturer=device.brand,
|
||||||
|
model=device.model,
|
||||||
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def native_value(
|
||||||
|
self,
|
||||||
|
) -> StateType:
|
||||||
|
"""Return the value reported by the device."""
|
||||||
|
device = self.coordinator.data.get(self._device.id)
|
||||||
|
if device is None:
|
||||||
|
_LOGGER.error("Device %s not found", self._device.id)
|
||||||
|
return None
|
||||||
|
|
||||||
|
for sensor in self._device.sensors:
|
||||||
|
if sensor.id == self.entity_description.key:
|
||||||
|
return sensor.value
|
||||||
|
return None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def available(self) -> bool:
|
||||||
|
"""Return whether the sensor is available."""
|
||||||
|
device = self.coordinator.data.get(self._device.id)
|
||||||
|
if device is None:
|
||||||
|
return False
|
||||||
|
return self.native_value is not None
|
||||||
|
|
||||||
|
|
||||||
class TibberSensor(SensorEntity):
|
class TibberSensor(SensorEntity):
|
||||||
"""Representation of a generic Tibber sensor."""
|
"""Representation of a generic Tibber sensor."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(
|
def __init__(self, *args: Any, tibber_home: TibberHome, **kwargs: Any) -> None:
|
||||||
self, *args: Any, tibber_home: tibber.TibberHome, **kwargs: Any
|
|
||||||
) -> None:
|
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self._tibber_home = tibber_home
|
self._tibber_home = tibber_home
|
||||||
@@ -366,7 +515,7 @@ class TibberSensorElPrice(TibberSensor):
|
|||||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||||
_attr_translation_key = "electricity_price"
|
_attr_translation_key = "electricity_price"
|
||||||
|
|
||||||
def __init__(self, tibber_home: tibber.TibberHome) -> None:
|
def __init__(self, tibber_home: TibberHome) -> None:
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
super().__init__(tibber_home=tibber_home)
|
super().__init__(tibber_home=tibber_home)
|
||||||
self._last_updated: datetime.datetime | None = None
|
self._last_updated: datetime.datetime | None = None
|
||||||
@@ -443,7 +592,7 @@ class TibberDataSensor(TibberSensor, CoordinatorEntity[TibberDataCoordinator]):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
tibber_home: tibber.TibberHome,
|
tibber_home: TibberHome,
|
||||||
coordinator: TibberDataCoordinator,
|
coordinator: TibberDataCoordinator,
|
||||||
entity_description: SensorEntityDescription,
|
entity_description: SensorEntityDescription,
|
||||||
) -> None:
|
) -> None:
|
||||||
@@ -470,7 +619,7 @@ class TibberSensorRT(TibberSensor, CoordinatorEntity["TibberRtDataCoordinator"])
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
tibber_home: tibber.TibberHome,
|
tibber_home: TibberHome,
|
||||||
description: SensorEntityDescription,
|
description: SensorEntityDescription,
|
||||||
initial_state: float,
|
initial_state: float,
|
||||||
coordinator: TibberRtDataCoordinator,
|
coordinator: TibberRtDataCoordinator,
|
||||||
@@ -532,7 +681,7 @@ class TibberRtEntityCreator:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
tibber_home: tibber.TibberHome,
|
tibber_home: TibberHome,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the data handler."""
|
"""Initialize the data handler."""
|
||||||
@@ -618,7 +767,7 @@ class TibberRtDataCoordinator(DataUpdateCoordinator): # pylint: disable=hass-en
|
|||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
add_sensor_callback: Callable[[TibberRtDataCoordinator, Any], None],
|
add_sensor_callback: Callable[[TibberRtDataCoordinator, Any], None],
|
||||||
tibber_home: tibber.TibberHome,
|
tibber_home: TibberHome,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the data handler."""
|
"""Initialize the data handler."""
|
||||||
self._add_sensor_callback = add_sensor_callback
|
self._add_sensor_callback = add_sensor_callback
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from homeassistant.core import (
|
|||||||
from homeassistant.exceptions import ServiceValidationError
|
from homeassistant.exceptions import ServiceValidationError
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import API_TYPE_GRAPHQL, DOMAIN
|
||||||
|
|
||||||
PRICE_SERVICE_NAME = "get_prices"
|
PRICE_SERVICE_NAME = "get_prices"
|
||||||
ATTR_START: Final = "start"
|
ATTR_START: Final = "start"
|
||||||
@@ -33,7 +33,15 @@ SERVICE_SCHEMA: Final = vol.Schema(
|
|||||||
|
|
||||||
|
|
||||||
async def __get_prices(call: ServiceCall) -> ServiceResponse:
|
async def __get_prices(call: ServiceCall) -> ServiceResponse:
|
||||||
tibber_connection = call.hass.data[DOMAIN]
|
domain_data = call.hass.data.get(DOMAIN, {})
|
||||||
|
runtime = domain_data.get(API_TYPE_GRAPHQL)
|
||||||
|
if runtime is None:
|
||||||
|
raise ServiceValidationError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="graphql_required",
|
||||||
|
)
|
||||||
|
|
||||||
|
tibber_connection = runtime.tibber
|
||||||
|
|
||||||
start = __get_date(call.data.get(ATTR_START), "start")
|
start = __get_date(call.data.get(ATTR_START), "start")
|
||||||
end = __get_date(call.data.get(ATTR_END), "end")
|
end = __get_date(call.data.get(ATTR_END), "end")
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
{
|
{
|
||||||
"config": {
|
"config": {
|
||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_service%]",
|
||||||
|
"missing_configuration": "[%key:common::config_flow::abort::oauth2_missing_configuration%]",
|
||||||
|
"missing_credentials": "Add Tibber Data API application credentials under Application Credentials before continuing. See {application_credentials_url} for guidance and {data_api_url} for API documentation.",
|
||||||
|
"oauth_invalid_token": "[%key:common::config_flow::abort::oauth2_error%]"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
|
||||||
@@ -9,11 +12,21 @@
|
|||||||
"timeout": "[%key:common::config_flow::error::timeout_connect%]"
|
"timeout": "[%key:common::config_flow::error::timeout_connect%]"
|
||||||
},
|
},
|
||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"graphql": {
|
||||||
"data": {
|
"data": {
|
||||||
"access_token": "[%key:common::config_flow::data::access_token%]"
|
"access_token": "[%key:common::config_flow::data::access_token%]"
|
||||||
},
|
},
|
||||||
"description": "Enter your access token from {url}"
|
"description": "Enter your access token from {url}"
|
||||||
|
},
|
||||||
|
"reauth_confirm": {
|
||||||
|
"description": "Reconnect your Tibber account to refresh access.",
|
||||||
|
"title": "[%key:common::config_flow::title::reauth%]"
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"data": {
|
||||||
|
"api_type": "API type"
|
||||||
|
},
|
||||||
|
"description": "Select which Tibber API you want to configure. See {url} for documentation."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -40,6 +53,37 @@
|
|||||||
"average_power": {
|
"average_power": {
|
||||||
"name": "Average power"
|
"name": "Average power"
|
||||||
},
|
},
|
||||||
|
"battery_battery_power": {
|
||||||
|
"name": "Battery power"
|
||||||
|
},
|
||||||
|
"battery_battery_state_of_charge": {
|
||||||
|
"name": "Battery state of charge"
|
||||||
|
},
|
||||||
|
"battery_stored_energy": {
|
||||||
|
"name": "Stored energy"
|
||||||
|
},
|
||||||
|
"charging_current_max": {
|
||||||
|
"name": "Maximum charging current"
|
||||||
|
},
|
||||||
|
"charging_current_offline_fallback": {
|
||||||
|
"name": "Offline fallback charging current"
|
||||||
|
},
|
||||||
|
"charging_status": {
|
||||||
|
"name": "Charging status",
|
||||||
|
"state": {
|
||||||
|
"charging": "Charging",
|
||||||
|
"idle": "Idle",
|
||||||
|
"unknown": "Unknown"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"connector_status": {
|
||||||
|
"name": "Connector status",
|
||||||
|
"state": {
|
||||||
|
"connected": "Connected",
|
||||||
|
"disconnected": "Disconnected",
|
||||||
|
"unknown": "Unknown"
|
||||||
|
}
|
||||||
|
},
|
||||||
"current_l1": {
|
"current_l1": {
|
||||||
"name": "Current L1"
|
"name": "Current L1"
|
||||||
},
|
},
|
||||||
@@ -55,6 +99,30 @@
|
|||||||
"estimated_hour_consumption": {
|
"estimated_hour_consumption": {
|
||||||
"name": "Estimated consumption current hour"
|
"name": "Estimated consumption current hour"
|
||||||
},
|
},
|
||||||
|
"ev_charger_charge_current": {
|
||||||
|
"name": "Charge current"
|
||||||
|
},
|
||||||
|
"ev_charger_charging_state": {
|
||||||
|
"name": "Charging state"
|
||||||
|
},
|
||||||
|
"ev_charger_power": {
|
||||||
|
"name": "Charging power"
|
||||||
|
},
|
||||||
|
"ev_charger_session_energy": {
|
||||||
|
"name": "Session energy"
|
||||||
|
},
|
||||||
|
"ev_charger_total_energy": {
|
||||||
|
"name": "Total energy"
|
||||||
|
},
|
||||||
|
"heat_pump_measured_temperature": {
|
||||||
|
"name": "Measured temperature"
|
||||||
|
},
|
||||||
|
"heat_pump_operation_mode": {
|
||||||
|
"name": "Operation mode"
|
||||||
|
},
|
||||||
|
"heat_pump_target_temperature": {
|
||||||
|
"name": "Target temperature"
|
||||||
|
},
|
||||||
"last_meter_consumption": {
|
"last_meter_consumption": {
|
||||||
"name": "Last meter consumption"
|
"name": "Last meter consumption"
|
||||||
},
|
},
|
||||||
@@ -88,9 +156,33 @@
|
|||||||
"power_production": {
|
"power_production": {
|
||||||
"name": "Power production"
|
"name": "Power production"
|
||||||
},
|
},
|
||||||
|
"range_remaining": {
|
||||||
|
"name": "Remaining range"
|
||||||
|
},
|
||||||
"signal_strength": {
|
"signal_strength": {
|
||||||
"name": "Signal strength"
|
"name": "Signal strength"
|
||||||
},
|
},
|
||||||
|
"solar_power": {
|
||||||
|
"name": "Solar power"
|
||||||
|
},
|
||||||
|
"solar_power_production": {
|
||||||
|
"name": "Power production"
|
||||||
|
},
|
||||||
|
"storage_state_of_charge": {
|
||||||
|
"name": "Storage state of charge"
|
||||||
|
},
|
||||||
|
"storage_target_state_of_charge": {
|
||||||
|
"name": "Storage target state of charge"
|
||||||
|
},
|
||||||
|
"thermostat_measured_temperature": {
|
||||||
|
"name": "Measured temperature"
|
||||||
|
},
|
||||||
|
"thermostat_operation_mode": {
|
||||||
|
"name": "Operation mode"
|
||||||
|
},
|
||||||
|
"thermostat_target_temperature": {
|
||||||
|
"name": "Target temperature"
|
||||||
|
},
|
||||||
"voltage_phase1": {
|
"voltage_phase1": {
|
||||||
"name": "Voltage phase1"
|
"name": "Voltage phase1"
|
||||||
},
|
},
|
||||||
@@ -103,6 +195,12 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
|
"oauth2_implementation_unavailable": {
|
||||||
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
|
},
|
||||||
|
"graphql_required": {
|
||||||
|
"message": "Configure the Tibber GraphQL API before calling this service."
|
||||||
|
},
|
||||||
"invalid_date": {
|
"invalid_date": {
|
||||||
"message": "Invalid datetime provided {date}"
|
"message": "Invalid datetime provided {date}"
|
||||||
},
|
},
|
||||||
@@ -110,6 +208,14 @@
|
|||||||
"message": "Timeout sending message with Tibber"
|
"message": "Timeout sending message with Tibber"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"selector": {
|
||||||
|
"api_type": {
|
||||||
|
"options": {
|
||||||
|
"data_api": "Data API (OAuth2)",
|
||||||
|
"graphql": "GraphQL API (access token)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"services": {
|
"services": {
|
||||||
"get_prices": {
|
"get_prices": {
|
||||||
"description": "Fetches hourly energy prices including price level.",
|
"description": "Fetches hourly energy prices including price level.",
|
||||||
|
|||||||
@@ -709,6 +709,7 @@ class DPCode(StrEnum):
|
|||||||
DEW_POINT_TEMP = "dew_point_temp"
|
DEW_POINT_TEMP = "dew_point_temp"
|
||||||
DISINFECTION = "disinfection"
|
DISINFECTION = "disinfection"
|
||||||
DO_NOT_DISTURB = "do_not_disturb"
|
DO_NOT_DISTURB = "do_not_disturb"
|
||||||
|
DOORBELL_PIC = "doorbell_pic"
|
||||||
DOORCONTACT_STATE = "doorcontact_state" # Status of door window sensor
|
DOORCONTACT_STATE = "doorcontact_state" # Status of door window sensor
|
||||||
DOORCONTACT_STATE_2 = "doorcontact_state_2"
|
DOORCONTACT_STATE_2 = "doorcontact_state_2"
|
||||||
DOORCONTACT_STATE_3 = "doorcontact_state_3"
|
DOORCONTACT_STATE_3 = "doorcontact_state_3"
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from contextlib import suppress
|
from typing import Any
|
||||||
import json
|
|
||||||
from typing import Any, cast
|
|
||||||
|
|
||||||
from tuya_sharing import CustomerDevice
|
from tuya_sharing import CustomerDevice
|
||||||
|
|
||||||
@@ -17,6 +15,13 @@ from homeassistant.util import dt as dt_util
|
|||||||
from . import TuyaConfigEntry
|
from . import TuyaConfigEntry
|
||||||
from .const import DOMAIN, DPCode
|
from .const import DOMAIN, DPCode
|
||||||
|
|
||||||
|
_REDACTED_DPCODES = {
|
||||||
|
DPCode.ALARM_MESSAGE,
|
||||||
|
DPCode.ALARM_MSG,
|
||||||
|
DPCode.DOORBELL_PIC,
|
||||||
|
DPCode.MOVEMENT_DETECT_PIC,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def async_get_config_entry_diagnostics(
|
async def async_get_config_entry_diagnostics(
|
||||||
hass: HomeAssistant, entry: TuyaConfigEntry
|
hass: HomeAssistant, entry: TuyaConfigEntry
|
||||||
@@ -97,34 +102,24 @@ def _async_device_as_dict(
|
|||||||
# Gather Tuya states
|
# Gather Tuya states
|
||||||
for dpcode, value in device.status.items():
|
for dpcode, value in device.status.items():
|
||||||
# These statuses may contain sensitive information, redact these..
|
# These statuses may contain sensitive information, redact these..
|
||||||
if dpcode in {DPCode.ALARM_MESSAGE, DPCode.MOVEMENT_DETECT_PIC}:
|
if dpcode in _REDACTED_DPCODES:
|
||||||
data["status"][dpcode] = REDACTED
|
data["status"][dpcode] = REDACTED
|
||||||
continue
|
continue
|
||||||
|
|
||||||
with suppress(ValueError, TypeError):
|
|
||||||
value = json.loads(value)
|
|
||||||
data["status"][dpcode] = value
|
data["status"][dpcode] = value
|
||||||
|
|
||||||
# Gather Tuya functions
|
# Gather Tuya functions
|
||||||
for function in device.function.values():
|
for function in device.function.values():
|
||||||
value = function.values
|
|
||||||
with suppress(ValueError, TypeError, AttributeError):
|
|
||||||
value = json.loads(cast(str, function.values))
|
|
||||||
|
|
||||||
data["function"][function.code] = {
|
data["function"][function.code] = {
|
||||||
"type": function.type,
|
"type": function.type,
|
||||||
"value": value,
|
"value": function.values,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Gather Tuya status ranges
|
# Gather Tuya status ranges
|
||||||
for status_range in device.status_range.values():
|
for status_range in device.status_range.values():
|
||||||
value = status_range.values
|
|
||||||
with suppress(ValueError, TypeError, AttributeError):
|
|
||||||
value = json.loads(status_range.values)
|
|
||||||
|
|
||||||
data["status_range"][status_range.code] = {
|
data["status_range"][status_range.code] = {
|
||||||
"type": status_range.type,
|
"type": status_range.type,
|
||||||
"value": value,
|
"value": status_range.values,
|
||||||
}
|
}
|
||||||
|
|
||||||
# Gather information how this Tuya device is represented in Home Assistant
|
# Gather information how this Tuya device is represented in Home Assistant
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
from homeassistant.util import color as color_util
|
from homeassistant.util import color as color_util
|
||||||
|
from homeassistant.util.json import json_loads_object
|
||||||
|
|
||||||
from . import TuyaConfigEntry
|
from . import TuyaConfigEntry
|
||||||
from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode, DPType, WorkMode
|
from .const import TUYA_DISCOVERY_NEW, DeviceCategory, DPCode, DPType, WorkMode
|
||||||
@@ -499,11 +500,11 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
|
|||||||
values = self.device.status_range[dpcode].values
|
values = self.device.status_range[dpcode].values
|
||||||
|
|
||||||
# Fetch color data type information
|
# Fetch color data type information
|
||||||
if function_data := json.loads(values):
|
if function_data := json_loads_object(values):
|
||||||
self._color_data_type = ColorTypeData(
|
self._color_data_type = ColorTypeData(
|
||||||
h_type=IntegerTypeData(dpcode, **function_data["h"]),
|
h_type=IntegerTypeData(dpcode, **cast(dict, function_data["h"])),
|
||||||
s_type=IntegerTypeData(dpcode, **function_data["s"]),
|
s_type=IntegerTypeData(dpcode, **cast(dict, function_data["s"])),
|
||||||
v_type=IntegerTypeData(dpcode, **function_data["v"]),
|
v_type=IntegerTypeData(dpcode, **cast(dict, function_data["v"])),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# If no type is found, use a default one
|
# If no type is found, use a default one
|
||||||
@@ -770,12 +771,12 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
|
|||||||
if not (status_data := self.device.status[self._color_data_dpcode]):
|
if not (status_data := self.device.status[self._color_data_dpcode]):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not (status := json.loads(status_data)):
|
if not (status := json_loads_object(status_data)):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return ColorData(
|
return ColorData(
|
||||||
type_data=self._color_data_type,
|
type_data=self._color_data_type,
|
||||||
h_value=status["h"],
|
h_value=cast(int, status["h"]),
|
||||||
s_value=status["s"],
|
s_value=cast(int, status["s"]),
|
||||||
v_value=status["v"],
|
v_value=cast(int, status["v"]),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,12 +5,11 @@ from __future__ import annotations
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
import base64
|
import base64
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
import json
|
from typing import Any, Literal, Self, cast, overload
|
||||||
from typing import Any, Literal, Self, overload
|
|
||||||
|
|
||||||
from tuya_sharing import CustomerDevice
|
from tuya_sharing import CustomerDevice
|
||||||
|
|
||||||
from homeassistant.util.json import json_loads
|
from homeassistant.util.json import json_loads, json_loads_object
|
||||||
|
|
||||||
from .const import DPCode, DPType
|
from .const import DPCode, DPType
|
||||||
from .util import parse_dptype, remap_value
|
from .util import parse_dptype, remap_value
|
||||||
@@ -88,7 +87,7 @@ class IntegerTypeData(TypeInformation):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
|
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
|
||||||
"""Load JSON string and return a IntegerTypeData object."""
|
"""Load JSON string and return a IntegerTypeData object."""
|
||||||
if not (parsed := json.loads(data)):
|
if not (parsed := cast(dict[str, Any] | None, json_loads_object(data))):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
@@ -111,9 +110,9 @@ class BitmapTypeInformation(TypeInformation):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
|
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
|
||||||
"""Load JSON string and return a BitmapTypeInformation object."""
|
"""Load JSON string and return a BitmapTypeInformation object."""
|
||||||
if not (parsed := json.loads(data)):
|
if not (parsed := json_loads_object(data)):
|
||||||
return None
|
return None
|
||||||
return cls(dpcode, **parsed)
|
return cls(dpcode, **cast(dict[str, list[str]], parsed))
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -125,9 +124,9 @@ class EnumTypeData(TypeInformation):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
|
def from_json(cls, dpcode: DPCode, data: str) -> Self | None:
|
||||||
"""Load JSON string and return a EnumTypeData object."""
|
"""Load JSON string and return a EnumTypeData object."""
|
||||||
if not (parsed := json.loads(data)):
|
if not (parsed := json_loads_object(data)):
|
||||||
return None
|
return None
|
||||||
return cls(dpcode, **parsed)
|
return cls(dpcode, **cast(dict[str, list[str]], parsed))
|
||||||
|
|
||||||
|
|
||||||
_TYPE_INFORMATION_MAPPINGS: dict[DPType, type[TypeInformation]] = {
|
_TYPE_INFORMATION_MAPPINGS: dict[DPType, type[TypeInformation]] = {
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
"oauth2_implementation_unavailable": {
|
"oauth2_implementation_unavailable": {
|
||||||
"message": "OAuth2 implementation unavailable, will retry"
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,12 @@ from __future__ import annotations
|
|||||||
from pyvlx import PyVLX, PyVLXException
|
from pyvlx import PyVLX, PyVLXException
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_HOST, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import (
|
||||||
|
CONF_HOST,
|
||||||
|
CONF_MAC,
|
||||||
|
CONF_PASSWORD,
|
||||||
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
|
)
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall
|
from homeassistant.core import HomeAssistant, ServiceCall
|
||||||
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
from homeassistant.helpers import device_registry as dr, issue_registry as ir
|
||||||
|
|
||||||
@@ -30,6 +35,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: VeluxConfigEntry) -> boo
|
|||||||
|
|
||||||
entry.runtime_data = pyvlx
|
entry.runtime_data = pyvlx
|
||||||
|
|
||||||
|
connections = None
|
||||||
|
if (mac := entry.data.get(CONF_MAC)) is not None:
|
||||||
|
connections = {(dr.CONNECTION_NETWORK_MAC, mac)}
|
||||||
|
|
||||||
device_registry = dr.async_get(hass)
|
device_registry = dr.async_get(hass)
|
||||||
device_registry.async_get_or_create(
|
device_registry.async_get_or_create(
|
||||||
config_entry_id=entry.entry_id,
|
config_entry_id=entry.entry_id,
|
||||||
@@ -43,6 +52,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: VeluxConfigEntry) -> boo
|
|||||||
sw_version=(
|
sw_version=(
|
||||||
str(pyvlx.klf200.version.softwareversion) if pyvlx.klf200.version else None
|
str(pyvlx.klf200.version.softwareversion) if pyvlx.klf200.version else None
|
||||||
),
|
),
|
||||||
|
connections=connections,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def on_hass_stop(event):
|
async def on_hass_stop(event):
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|||||||
from . import VeluxConfigEntry
|
from . import VeluxConfigEntry
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
|
PARALLEL_UPDATES = 1
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
|||||||
@@ -56,37 +56,32 @@ class VeluxCover(VeluxEntity, CoverEntity):
|
|||||||
def __init__(self, node: OpeningDevice, config_entry_id: str) -> None:
|
def __init__(self, node: OpeningDevice, config_entry_id: str) -> None:
|
||||||
"""Initialize VeluxCover."""
|
"""Initialize VeluxCover."""
|
||||||
super().__init__(node, config_entry_id)
|
super().__init__(node, config_entry_id)
|
||||||
|
# Features common to all covers
|
||||||
|
self._attr_supported_features = (
|
||||||
|
CoverEntityFeature.OPEN
|
||||||
|
| CoverEntityFeature.CLOSE
|
||||||
|
| CoverEntityFeature.SET_POSITION
|
||||||
|
| CoverEntityFeature.STOP
|
||||||
|
)
|
||||||
# Window is the default device class for covers
|
# Window is the default device class for covers
|
||||||
self._attr_device_class = CoverDeviceClass.WINDOW
|
self._attr_device_class = CoverDeviceClass.WINDOW
|
||||||
if isinstance(node, Awning):
|
if isinstance(node, Awning):
|
||||||
self._attr_device_class = CoverDeviceClass.AWNING
|
self._attr_device_class = CoverDeviceClass.AWNING
|
||||||
if isinstance(node, Blind):
|
|
||||||
self._attr_device_class = CoverDeviceClass.BLIND
|
|
||||||
self._is_blind = True
|
|
||||||
if isinstance(node, GarageDoor):
|
if isinstance(node, GarageDoor):
|
||||||
self._attr_device_class = CoverDeviceClass.GARAGE
|
self._attr_device_class = CoverDeviceClass.GARAGE
|
||||||
if isinstance(node, Gate):
|
if isinstance(node, Gate):
|
||||||
self._attr_device_class = CoverDeviceClass.GATE
|
self._attr_device_class = CoverDeviceClass.GATE
|
||||||
if isinstance(node, RollerShutter):
|
if isinstance(node, RollerShutter):
|
||||||
self._attr_device_class = CoverDeviceClass.SHUTTER
|
self._attr_device_class = CoverDeviceClass.SHUTTER
|
||||||
|
if isinstance(node, Blind):
|
||||||
@property
|
self._attr_device_class = CoverDeviceClass.BLIND
|
||||||
def supported_features(self) -> CoverEntityFeature:
|
self._is_blind = True
|
||||||
"""Flag supported features."""
|
self._attr_supported_features |= (
|
||||||
supported_features = (
|
|
||||||
CoverEntityFeature.OPEN
|
|
||||||
| CoverEntityFeature.CLOSE
|
|
||||||
| CoverEntityFeature.SET_POSITION
|
|
||||||
| CoverEntityFeature.STOP
|
|
||||||
)
|
|
||||||
if self.current_cover_tilt_position is not None:
|
|
||||||
supported_features |= (
|
|
||||||
CoverEntityFeature.OPEN_TILT
|
CoverEntityFeature.OPEN_TILT
|
||||||
| CoverEntityFeature.CLOSE_TILT
|
| CoverEntityFeature.CLOSE_TILT
|
||||||
| CoverEntityFeature.SET_TILT_POSITION
|
| CoverEntityFeature.SET_TILT_POSITION
|
||||||
| CoverEntityFeature.STOP_TILT
|
| CoverEntityFeature.STOP_TILT
|
||||||
)
|
)
|
||||||
return supported_features
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_cover_position(self) -> int:
|
def current_cover_position(self) -> int:
|
||||||
|
|||||||
@@ -37,9 +37,7 @@ rules:
|
|||||||
entity-unavailable: todo
|
entity-unavailable: todo
|
||||||
integration-owner: done
|
integration-owner: done
|
||||||
log-when-unavailable: todo
|
log-when-unavailable: todo
|
||||||
parallel-updates:
|
parallel-updates: done
|
||||||
status: todo
|
|
||||||
comment: button still needs it
|
|
||||||
reauthentication-flow: todo
|
reauthentication-flow: todo
|
||||||
test-coverage:
|
test-coverage:
|
||||||
status: todo
|
status: todo
|
||||||
|
|||||||
@@ -13,5 +13,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/vesync",
|
"documentation": "https://www.home-assistant.io/integrations/vesync",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["pyvesync"],
|
"loggers": ["pyvesync"],
|
||||||
"requirements": ["pyvesync==3.2.1"]
|
"requirements": ["pyvesync==3.2.2"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,6 +144,11 @@ GLOBAL_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
|
|||||||
device_class=BinarySensorDeviceClass.DOOR,
|
device_class=BinarySensorDeviceClass.DOOR,
|
||||||
value_getter=lambda api: api.isValveOpen(),
|
value_getter=lambda api: api.isValveOpen(),
|
||||||
),
|
),
|
||||||
|
ViCareBinarySensorEntityDescription(
|
||||||
|
key="ventilation_frost_protection",
|
||||||
|
translation_key="ventilation_frost_protection",
|
||||||
|
value_getter=lambda api: api.getHeatExchangerFrostProtectionActive(),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ CONF_HEATING_TYPE = "heating_type"
|
|||||||
DEFAULT_CACHE_DURATION = 60
|
DEFAULT_CACHE_DURATION = 60
|
||||||
|
|
||||||
VICARE_BAR = "bar"
|
VICARE_BAR = "bar"
|
||||||
|
VICARE_CELSIUS = "celsius"
|
||||||
VICARE_CUBIC_METER = "cubicMeter"
|
VICARE_CUBIC_METER = "cubicMeter"
|
||||||
VICARE_KW = "kilowatt"
|
VICARE_KW = "kilowatt"
|
||||||
VICARE_KWH = "kilowattHour"
|
VICARE_KWH = "kilowattHour"
|
||||||
|
|||||||
@@ -16,6 +16,15 @@
|
|||||||
"domestic_hot_water_pump": {
|
"domestic_hot_water_pump": {
|
||||||
"default": "mdi:pump"
|
"default": "mdi:pump"
|
||||||
},
|
},
|
||||||
|
"filter_hours": {
|
||||||
|
"default": "mdi:counter"
|
||||||
|
},
|
||||||
|
"filter_overdue_hours": {
|
||||||
|
"default": "mdi:counter"
|
||||||
|
},
|
||||||
|
"filter_remaining_hours": {
|
||||||
|
"default": "mdi:counter"
|
||||||
|
},
|
||||||
"frost_protection": {
|
"frost_protection": {
|
||||||
"default": "mdi:snowflake"
|
"default": "mdi:snowflake"
|
||||||
},
|
},
|
||||||
@@ -28,6 +37,12 @@
|
|||||||
"solar_pump": {
|
"solar_pump": {
|
||||||
"default": "mdi:pump"
|
"default": "mdi:pump"
|
||||||
},
|
},
|
||||||
|
"supply_fan_hours": {
|
||||||
|
"default": "mdi:counter"
|
||||||
|
},
|
||||||
|
"supply_fan_speed": {
|
||||||
|
"default": "mdi:rotate-right"
|
||||||
|
},
|
||||||
"valve": {
|
"valve": {
|
||||||
"default": "mdi:pipe-valve"
|
"default": "mdi:pipe-valve"
|
||||||
}
|
}
|
||||||
@@ -101,6 +116,12 @@
|
|||||||
"ess_state_of_charge": {
|
"ess_state_of_charge": {
|
||||||
"default": "mdi:home-battery"
|
"default": "mdi:home-battery"
|
||||||
},
|
},
|
||||||
|
"heating_rod_hours": {
|
||||||
|
"default": "mdi:counter"
|
||||||
|
},
|
||||||
|
"heating_rod_starts": {
|
||||||
|
"default": "mdi:counter"
|
||||||
|
},
|
||||||
"pcc_energy_consumption": {
|
"pcc_energy_consumption": {
|
||||||
"default": "mdi:transmission-tower-export"
|
"default": "mdi:transmission-tower-export"
|
||||||
},
|
},
|
||||||
@@ -116,9 +137,15 @@
|
|||||||
"valve_position": {
|
"valve_position": {
|
||||||
"default": "mdi:pipe-valve"
|
"default": "mdi:pipe-valve"
|
||||||
},
|
},
|
||||||
|
"ventilation_input_volumeflow": {
|
||||||
|
"default": "mdi:air-filter"
|
||||||
|
},
|
||||||
"ventilation_level": {
|
"ventilation_level": {
|
||||||
"default": "mdi:fan"
|
"default": "mdi:fan"
|
||||||
},
|
},
|
||||||
|
"ventilation_output_volumeflow": {
|
||||||
|
"default": "mdi:air-filter"
|
||||||
|
},
|
||||||
"volumetric_flow": {
|
"volumetric_flow": {
|
||||||
"default": "mdi:gauge"
|
"default": "mdi:gauge"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -12,5 +12,5 @@
|
|||||||
"integration_type": "hub",
|
"integration_type": "hub",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["PyViCare"],
|
"loggers": ["PyViCare"],
|
||||||
"requirements": ["PyViCare==2.54.0"]
|
"requirements": ["PyViCare==2.55.0"]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ from homeassistant.components.sensor import (
|
|||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
|
REVOLUTIONS_PER_MINUTE,
|
||||||
EntityCategory,
|
EntityCategory,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
UnitOfMass,
|
UnitOfMass,
|
||||||
@@ -42,6 +44,7 @@ from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
VICARE_BAR,
|
VICARE_BAR,
|
||||||
|
VICARE_CELSIUS,
|
||||||
VICARE_CUBIC_METER,
|
VICARE_CUBIC_METER,
|
||||||
VICARE_KW,
|
VICARE_KW,
|
||||||
VICARE_KWH,
|
VICARE_KWH,
|
||||||
@@ -56,7 +59,9 @@ from .utils import (
|
|||||||
get_burners,
|
get_burners,
|
||||||
get_circuits,
|
get_circuits,
|
||||||
get_compressors,
|
get_compressors,
|
||||||
|
get_condensers,
|
||||||
get_device_serial,
|
get_device_serial,
|
||||||
|
get_evaporators,
|
||||||
is_supported,
|
is_supported,
|
||||||
normalize_state,
|
normalize_state,
|
||||||
)
|
)
|
||||||
@@ -74,6 +79,7 @@ VICARE_UNIT_TO_DEVICE_CLASS = {
|
|||||||
|
|
||||||
VICARE_UNIT_TO_HA_UNIT = {
|
VICARE_UNIT_TO_HA_UNIT = {
|
||||||
VICARE_BAR: UnitOfPressure.BAR,
|
VICARE_BAR: UnitOfPressure.BAR,
|
||||||
|
VICARE_CELSIUS: UnitOfTemperature.CELSIUS,
|
||||||
VICARE_CUBIC_METER: UnitOfVolume.CUBIC_METERS,
|
VICARE_CUBIC_METER: UnitOfVolume.CUBIC_METERS,
|
||||||
VICARE_KW: UnitOfPower.KILO_WATT,
|
VICARE_KW: UnitOfPower.KILO_WATT,
|
||||||
VICARE_KWH: UnitOfEnergy.KILO_WATT_HOUR,
|
VICARE_KWH: UnitOfEnergy.KILO_WATT_HOUR,
|
||||||
@@ -111,6 +117,14 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
|||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="outside_humidity",
|
||||||
|
translation_key="outside_humidity",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
value_getter=lambda api: api.getOutsideHumidity(),
|
||||||
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
ViCareSensorEntityDescription(
|
ViCareSensorEntityDescription(
|
||||||
key="return_temperature",
|
key="return_temperature",
|
||||||
translation_key="return_temperature",
|
translation_key="return_temperature",
|
||||||
@@ -992,6 +1006,101 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
|||||||
value_getter=lambda api: api.getHydraulicSeparatorTemperature(),
|
value_getter=lambda api: api.getHydraulicSeparatorTemperature(),
|
||||||
),
|
),
|
||||||
SUPPLY_TEMPERATURE_SENSOR,
|
SUPPLY_TEMPERATURE_SENSOR,
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="supply_humidity",
|
||||||
|
translation_key="supply_humidity",
|
||||||
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_getter=lambda api: api.getSupplyHumidity(),
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="supply_fan_hours",
|
||||||
|
translation_key="supply_fan_hours",
|
||||||
|
native_unit_of_measurement=UnitOfTime.HOURS,
|
||||||
|
value_getter=lambda api: api.getSupplyFanHours(),
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="supply_fan_speed",
|
||||||
|
translation_key="supply_fan_speed",
|
||||||
|
native_unit_of_measurement=REVOLUTIONS_PER_MINUTE,
|
||||||
|
value_getter=lambda api: api.getSupplyFanSpeed(),
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="filter_hours",
|
||||||
|
translation_key="filter_hours",
|
||||||
|
native_unit_of_measurement=UnitOfTime.HOURS,
|
||||||
|
value_getter=lambda api: api.getFilterHours(),
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="filter_remaining_hours",
|
||||||
|
translation_key="filter_remaining_hours",
|
||||||
|
native_unit_of_measurement=UnitOfTime.HOURS,
|
||||||
|
value_getter=lambda api: api.getFilterRemainingHours(),
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="filter_overdue_hours",
|
||||||
|
translation_key="filter_overdue_hours",
|
||||||
|
native_unit_of_measurement=UnitOfTime.HOURS,
|
||||||
|
value_getter=lambda api: api.getFilterOverdueHours(),
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="pm01",
|
||||||
|
device_class=SensorDeviceClass.PM1,
|
||||||
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_getter=lambda api: api.getAirborneDustPM1(),
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="pm02",
|
||||||
|
device_class=SensorDeviceClass.PM25,
|
||||||
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_getter=lambda api: api.getAirborneDustPM2d5(),
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="pm04",
|
||||||
|
device_class=SensorDeviceClass.PM4,
|
||||||
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_getter=lambda api: api.getAirborneDustPM4(),
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="pm10",
|
||||||
|
device_class=SensorDeviceClass.PM10,
|
||||||
|
native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
value_getter=lambda api: api.getAirborneDustPM10(),
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="ventilation_input_volumeflow",
|
||||||
|
translation_key="ventilation_input_volumeflow",
|
||||||
|
native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
|
||||||
|
value_getter=lambda api: api.getSupplyVolumeFlow(),
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="ventilation_output_volumeflow",
|
||||||
|
translation_key="ventilation_output_volumeflow",
|
||||||
|
native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
|
||||||
|
value_getter=lambda api: api.getExhaustVolumeFlow(),
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
CIRCUIT_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
CIRCUIT_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
||||||
@@ -1090,6 +1199,84 @@ COMPRESSOR_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
|||||||
value_getter=lambda api: normalize_state(api.getPhase()),
|
value_getter=lambda api: normalize_state(api.getPhase()),
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="compressor_inlet_temperature",
|
||||||
|
translation_key="compressor_inlet_temperature",
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getCompressorInletTemperature(),
|
||||||
|
unit_getter=lambda api: api.getCompressorInletTemperatureUnit(),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="compressor_outlet_temperature",
|
||||||
|
translation_key="compressor_outlet_temperature",
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getCompressorOutletTemperature(),
|
||||||
|
unit_getter=lambda api: api.getCompressorOutletTemperatureUnit(),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="compressor_inlet_pressure",
|
||||||
|
translation_key="compressor_inlet_pressure",
|
||||||
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
|
native_unit_of_measurement=UnitOfPressure.BAR,
|
||||||
|
value_getter=lambda api: api.getCompressorInletPressure(),
|
||||||
|
unit_getter=lambda api: api.getCompressorInletPressureUnit(),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="compressor_outlet_pressure",
|
||||||
|
translation_key="compressor_outlet_pressure",
|
||||||
|
device_class=SensorDeviceClass.PRESSURE,
|
||||||
|
native_unit_of_measurement=UnitOfPressure.BAR,
|
||||||
|
value_getter=lambda api: api.getCompressorOutletPressure(),
|
||||||
|
unit_getter=lambda api: api.getCompressorOutletPressureUnit(),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
CONDENSER_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="condenser_liquid_temperature",
|
||||||
|
translation_key="condenser_liquid_temperature",
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getCondensorLiquidTemperature(),
|
||||||
|
unit_getter=lambda api: api.getCondensorLiquidTemperatureUnit(),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="condenser_subcooling_temperature",
|
||||||
|
translation_key="condenser_subcooling_temperature",
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getCondensorSubcoolingTemperature(),
|
||||||
|
unit_getter=lambda api: api.getCondensorSubcoolingTemperatureUnit(),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
EVAPORATOR_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="evaporator_overheat_temperature",
|
||||||
|
translation_key="evaporator_overheat_temperature",
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getEvaporatorOverheatTemperature(),
|
||||||
|
unit_getter=lambda api: api.getEvaporatorOverheatTemperatureUnit(),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
|
ViCareSensorEntityDescription(
|
||||||
|
key="evaporator_liquid_temperature",
|
||||||
|
translation_key="evaporator_liquid_temperature",
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
value_getter=lambda api: api.getEvaporatorLiquidTemperature(),
|
||||||
|
unit_getter=lambda api: api.getEvaporatorLiquidTemperatureUnit(),
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -1116,6 +1303,8 @@ def _build_entities(
|
|||||||
(get_circuits(device.api), CIRCUIT_SENSORS),
|
(get_circuits(device.api), CIRCUIT_SENSORS),
|
||||||
(get_burners(device.api), BURNER_SENSORS),
|
(get_burners(device.api), BURNER_SENSORS),
|
||||||
(get_compressors(device.api), COMPRESSOR_SENSORS),
|
(get_compressors(device.api), COMPRESSOR_SENSORS),
|
||||||
|
(get_condensers(device.api), CONDENSER_SENSORS),
|
||||||
|
(get_evaporators(device.api), EVAPORATOR_SENSORS),
|
||||||
):
|
):
|
||||||
entities.extend(
|
entities.extend(
|
||||||
ViCareSensor(
|
ViCareSensor(
|
||||||
|
|||||||
@@ -78,6 +78,9 @@
|
|||||||
},
|
},
|
||||||
"valve": {
|
"valve": {
|
||||||
"name": "Valve"
|
"name": "Valve"
|
||||||
|
},
|
||||||
|
"ventilation_frost_protection": {
|
||||||
|
"name": "Ventilation frost protection"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"button": {
|
"button": {
|
||||||
@@ -212,6 +215,18 @@
|
|||||||
"compressor_hours_loadclass5": {
|
"compressor_hours_loadclass5": {
|
||||||
"name": "Compressor hours load class 5"
|
"name": "Compressor hours load class 5"
|
||||||
},
|
},
|
||||||
|
"compressor_inlet_pressure": {
|
||||||
|
"name": "Compressor inlet pressure"
|
||||||
|
},
|
||||||
|
"compressor_inlet_temperature": {
|
||||||
|
"name": "Compressor inlet temperature"
|
||||||
|
},
|
||||||
|
"compressor_outlet_pressure": {
|
||||||
|
"name": "Compressor outlet pressure"
|
||||||
|
},
|
||||||
|
"compressor_outlet_temperature": {
|
||||||
|
"name": "Compressor outlet temperature"
|
||||||
|
},
|
||||||
"compressor_phase": {
|
"compressor_phase": {
|
||||||
"name": "Compressor phase",
|
"name": "Compressor phase",
|
||||||
"state": {
|
"state": {
|
||||||
@@ -229,6 +244,12 @@
|
|||||||
"compressor_starts": {
|
"compressor_starts": {
|
||||||
"name": "Compressor starts"
|
"name": "Compressor starts"
|
||||||
},
|
},
|
||||||
|
"condenser_liquid_temperature": {
|
||||||
|
"name": "Condenser liquid temperature"
|
||||||
|
},
|
||||||
|
"condenser_subcooling_temperature": {
|
||||||
|
"name": "Condenser subcooling temperature"
|
||||||
|
},
|
||||||
"dhw_storage_bottom_temperature": {
|
"dhw_storage_bottom_temperature": {
|
||||||
"name": "DHW storage bottom temperature"
|
"name": "DHW storage bottom temperature"
|
||||||
},
|
},
|
||||||
@@ -303,6 +324,21 @@
|
|||||||
"standby": "[%key:common::state::standby%]"
|
"standby": "[%key:common::state::standby%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"evaporator_liquid_temperature": {
|
||||||
|
"name": "Evaporator liquid temperature"
|
||||||
|
},
|
||||||
|
"evaporator_overheat_temperature": {
|
||||||
|
"name": "Evaporator overheat temperature"
|
||||||
|
},
|
||||||
|
"filter_hours": {
|
||||||
|
"name": "Filter hours"
|
||||||
|
},
|
||||||
|
"filter_overdue_hours": {
|
||||||
|
"name": "Filter overdue hours"
|
||||||
|
},
|
||||||
|
"filter_remaining_hours": {
|
||||||
|
"name": "Filter remaining hours"
|
||||||
|
},
|
||||||
"fuel_need": {
|
"fuel_need": {
|
||||||
"name": "Fuel need"
|
"name": "Fuel need"
|
||||||
},
|
},
|
||||||
@@ -396,6 +432,9 @@
|
|||||||
"hydraulic_separator_temperature": {
|
"hydraulic_separator_temperature": {
|
||||||
"name": "Hydraulic separator temperature"
|
"name": "Hydraulic separator temperature"
|
||||||
},
|
},
|
||||||
|
"outside_humidity": {
|
||||||
|
"name": "Outside humidity"
|
||||||
|
},
|
||||||
"outside_temperature": {
|
"outside_temperature": {
|
||||||
"name": "Outside temperature"
|
"name": "Outside temperature"
|
||||||
},
|
},
|
||||||
@@ -499,6 +538,15 @@
|
|||||||
"spf_total": {
|
"spf_total": {
|
||||||
"name": "Seasonal performance factor"
|
"name": "Seasonal performance factor"
|
||||||
},
|
},
|
||||||
|
"supply_fan_hours": {
|
||||||
|
"name": "Supply fan hours"
|
||||||
|
},
|
||||||
|
"supply_fan_speed": {
|
||||||
|
"name": "Supply fan speed"
|
||||||
|
},
|
||||||
|
"supply_humidity": {
|
||||||
|
"name": "Supply humidity"
|
||||||
|
},
|
||||||
"supply_pressure": {
|
"supply_pressure": {
|
||||||
"name": "Supply pressure"
|
"name": "Supply pressure"
|
||||||
},
|
},
|
||||||
@@ -508,6 +556,9 @@
|
|||||||
"valve_position": {
|
"valve_position": {
|
||||||
"name": "Valve position"
|
"name": "Valve position"
|
||||||
},
|
},
|
||||||
|
"ventilation_input_volumeflow": {
|
||||||
|
"name": "Ventilation input volume flow"
|
||||||
|
},
|
||||||
"ventilation_level": {
|
"ventilation_level": {
|
||||||
"name": "Ventilation level",
|
"name": "Ventilation level",
|
||||||
"state": {
|
"state": {
|
||||||
@@ -518,6 +569,9 @@
|
|||||||
"standby": "[%key:common::state::standby%]"
|
"standby": "[%key:common::state::standby%]"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"ventilation_output_volumeflow": {
|
||||||
|
"name": "Ventilation output volume flow"
|
||||||
|
},
|
||||||
"ventilation_reason": {
|
"ventilation_reason": {
|
||||||
"name": "Ventilation reason",
|
"name": "Ventilation reason",
|
||||||
"state": {
|
"state": {
|
||||||
|
|||||||
@@ -130,6 +130,28 @@ def get_compressors(device: PyViCareDevice) -> list[PyViCareHeatingDeviceCompone
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def get_condensers(device: PyViCareDevice) -> list[PyViCareHeatingDeviceComponent]:
|
||||||
|
"""Return the list of condensers."""
|
||||||
|
try:
|
||||||
|
return device.condensors
|
||||||
|
except PyViCareNotSupportedFeatureError:
|
||||||
|
_LOGGER.debug("No condensers found")
|
||||||
|
except AttributeError as error:
|
||||||
|
_LOGGER.debug("No condensers found: %s", error)
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
def get_evaporators(device: PyViCareDevice) -> list[PyViCareHeatingDeviceComponent]:
|
||||||
|
"""Return the list of evaporators."""
|
||||||
|
try:
|
||||||
|
return device.evaporators
|
||||||
|
except PyViCareNotSupportedFeatureError:
|
||||||
|
_LOGGER.debug("No evaporators found")
|
||||||
|
except AttributeError as error:
|
||||||
|
_LOGGER.debug("No evaporators found: %s", error)
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def filter_state(state: str) -> str | None:
|
def filter_state(state: str) -> str | None:
|
||||||
"""Return the state if not 'nothing' or 'unknown'."""
|
"""Return the state if not 'nothing' or 'unknown'."""
|
||||||
return None if state in ("nothing", "unknown") else state
|
return None if state in ("nothing", "unknown") else state
|
||||||
|
|||||||
@@ -363,7 +363,7 @@
|
|||||||
"message": "Unable to retrieve vehicle details."
|
"message": "Unable to retrieve vehicle details."
|
||||||
},
|
},
|
||||||
"oauth2_implementation_unavailable": {
|
"oauth2_implementation_unavailable": {
|
||||||
"message": "OAuth2 implementation unavailable, will retry"
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
},
|
},
|
||||||
"unauthorized": {
|
"unauthorized": {
|
||||||
"message": "Authentication failed. {message}"
|
"message": "Authentication failed. {message}"
|
||||||
|
|||||||
@@ -334,7 +334,7 @@
|
|||||||
},
|
},
|
||||||
"exceptions": {
|
"exceptions": {
|
||||||
"oauth2_implementation_unavailable": {
|
"oauth2_implementation_unavailable": {
|
||||||
"message": "OAuth2 implementation unavailable, will retry"
|
"message": "[%key:common::exceptions::oauth2_implementation_unavailable::message%]"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,12 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import XboxConfigEntry, XboxUpdateCoordinator
|
from .coordinator import (
|
||||||
|
XboxConfigEntry,
|
||||||
|
XboxConsolesCoordinator,
|
||||||
|
XboxCoordinators,
|
||||||
|
XboxUpdateCoordinator,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -30,7 +35,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: XboxConfigEntry) -> bool
|
|||||||
coordinator = XboxUpdateCoordinator(hass, entry)
|
coordinator = XboxUpdateCoordinator(hass, entry)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
entry.runtime_data = coordinator
|
consoles = XboxConsolesCoordinator(hass, entry, coordinator)
|
||||||
|
|
||||||
|
entry.runtime_data = XboxCoordinators(coordinator, consoles)
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
@@ -53,16 +60,14 @@ async def async_migrate_unique_id(hass: HomeAssistant, entry: XboxConfigEntry) -
|
|||||||
if entry.version == 1 and entry.minor_version < 2:
|
if entry.version == 1 and entry.minor_version < 2:
|
||||||
# Migrate unique_id from `xbox` to account xuid and
|
# Migrate unique_id from `xbox` to account xuid and
|
||||||
# change generic entry name to user's gamertag
|
# change generic entry name to user's gamertag
|
||||||
|
coordinator = entry.runtime_data.status
|
||||||
|
xuid = coordinator.client.xuid
|
||||||
|
gamertag = coordinator.data.presence[xuid].gamertag
|
||||||
|
|
||||||
return hass.config_entries.async_update_entry(
|
return hass.config_entries.async_update_entry(
|
||||||
entry,
|
entry,
|
||||||
unique_id=entry.runtime_data.client.xuid,
|
unique_id=xuid,
|
||||||
title=(
|
title=(gamertag if entry.title == "Home Assistant Cloud" else entry.title),
|
||||||
entry.runtime_data.data.presence[
|
|
||||||
entry.runtime_data.client.xuid
|
|
||||||
].gamertag
|
|
||||||
if entry.title == "Home Assistant Cloud"
|
|
||||||
else entry.title
|
|
||||||
),
|
|
||||||
minor_version=2,
|
minor_version=2,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ class XboxBinarySensorEntityDescription(
|
|||||||
"""Xbox binary sensor description."""
|
"""Xbox binary sensor description."""
|
||||||
|
|
||||||
is_on_fn: Callable[[Person], bool | None]
|
is_on_fn: Callable[[Person], bool | None]
|
||||||
deprecated: bool | None = None
|
|
||||||
|
|
||||||
|
|
||||||
def profile_attributes(person: Person, _: Title | None) -> dict[str, Any]:
|
def profile_attributes(person: Person, _: Title | None) -> dict[str, Any]:
|
||||||
@@ -112,7 +111,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Xbox Live friends."""
|
"""Set up Xbox Live friends."""
|
||||||
xuids_added: set[str] = set()
|
xuids_added: set[str] = set()
|
||||||
coordinator = entry.runtime_data
|
coordinator = entry.runtime_data.status
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def add_entities() -> None:
|
def add_entities() -> None:
|
||||||
@@ -120,16 +119,16 @@ async def async_setup_entry(
|
|||||||
|
|
||||||
current_xuids = set(coordinator.data.presence)
|
current_xuids = set(coordinator.data.presence)
|
||||||
if new_xuids := current_xuids - xuids_added:
|
if new_xuids := current_xuids - xuids_added:
|
||||||
for xuid in new_xuids:
|
async_add_entities(
|
||||||
async_add_entities(
|
[
|
||||||
[
|
XboxBinarySensorEntity(coordinator, xuid, description)
|
||||||
XboxBinarySensorEntity(coordinator, xuid, description)
|
for xuid in new_xuids
|
||||||
for description in SENSOR_DESCRIPTIONS
|
for description in SENSOR_DESCRIPTIONS
|
||||||
if check_deprecated_entity(
|
if check_deprecated_entity(
|
||||||
hass, xuid, description, BINARY_SENSOR_DOMAIN
|
hass, xuid, description, BINARY_SENSOR_DOMAIN
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
xuids_added |= new_xuids
|
xuids_added |= new_xuids
|
||||||
xuids_added &= current_xuids
|
xuids_added &= current_xuids
|
||||||
|
|
||||||
|
|||||||
@@ -4,5 +4,3 @@ DOMAIN = "xbox"
|
|||||||
|
|
||||||
OAUTH2_AUTHORIZE = "https://login.live.com/oauth20_authorize.srf"
|
OAUTH2_AUTHORIZE = "https://login.live.com/oauth20_authorize.srf"
|
||||||
OAUTH2_TOKEN = "https://login.live.com/oauth20_token.srf"
|
OAUTH2_TOKEN = "https://login.live.com/oauth20_token.srf"
|
||||||
|
|
||||||
EVENT_NEW_FAVORITE = "xbox/new_favorite"
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
type XboxConfigEntry = ConfigEntry[XboxUpdateCoordinator]
|
type XboxConfigEntry = ConfigEntry[XboxCoordinators]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
@@ -55,17 +55,25 @@ class XboxData:
|
|||||||
title_info: dict[str, Title] = field(default_factory=dict)
|
title_info: dict[str, Title] = field(default_factory=dict)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class XboxCoordinators:
|
||||||
|
"""Xbox coordinators."""
|
||||||
|
|
||||||
|
status: XboxUpdateCoordinator
|
||||||
|
consoles: XboxConsolesCoordinator
|
||||||
|
|
||||||
|
|
||||||
class XboxUpdateCoordinator(DataUpdateCoordinator[XboxData]):
|
class XboxUpdateCoordinator(DataUpdateCoordinator[XboxData]):
|
||||||
"""Store Xbox Console Status."""
|
"""Store Xbox Console Status."""
|
||||||
|
|
||||||
config_entry: ConfigEntry
|
config_entry: XboxConfigEntry
|
||||||
consoles: SmartglassConsoleList
|
consoles: SmartglassConsoleList
|
||||||
client: XboxLiveClient
|
client: XboxLiveClient
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config_entry: ConfigEntry,
|
config_entry: XboxConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize."""
|
"""Initialize."""
|
||||||
super().__init__(
|
super().__init__(
|
||||||
@@ -280,3 +288,43 @@ class XboxUpdateCoordinator(DataUpdateCoordinator[XboxData]):
|
|||||||
for entry in self.hass.config_entries.async_entries(DOMAIN)
|
for entry in self.hass.config_entries.async_entries(DOMAIN)
|
||||||
if entry.unique_id is not None
|
if entry.unique_id is not None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class XboxConsolesCoordinator(DataUpdateCoordinator[SmartglassConsoleList]):
|
||||||
|
"""Update list of Xbox consoles."""
|
||||||
|
|
||||||
|
config_entry: XboxConfigEntry
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: XboxConfigEntry,
|
||||||
|
coordinator: XboxUpdateCoordinator,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize."""
|
||||||
|
super().__init__(
|
||||||
|
hass,
|
||||||
|
_LOGGER,
|
||||||
|
config_entry=config_entry,
|
||||||
|
name=DOMAIN,
|
||||||
|
update_interval=timedelta(minutes=10),
|
||||||
|
)
|
||||||
|
self.client = coordinator.client
|
||||||
|
self.async_set_updated_data(coordinator.consoles)
|
||||||
|
|
||||||
|
async def _async_update_data(self) -> SmartglassConsoleList:
|
||||||
|
"""Fetch console data."""
|
||||||
|
|
||||||
|
try:
|
||||||
|
return await self.client.smartglass.get_console_list()
|
||||||
|
except TimeoutException as e:
|
||||||
|
raise UpdateFailed(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="timeout_exception",
|
||||||
|
) from e
|
||||||
|
except (RequestError, HTTPStatusError) as e:
|
||||||
|
_LOGGER.debug("Xbox exception:", exc_info=True)
|
||||||
|
raise UpdateFailed(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="request_exception",
|
||||||
|
) from e
|
||||||
|
|||||||
@@ -94,8 +94,7 @@ class XboxBaseEntity(CoordinatorEntity[XboxUpdateCoordinator]):
|
|||||||
"""Return entity specific state attributes."""
|
"""Return entity specific state attributes."""
|
||||||
return (
|
return (
|
||||||
fn(self.data, self.title_info)
|
fn(self.data, self.title_info)
|
||||||
if hasattr(self.entity_description, "attributes_fn")
|
if (fn := self.entity_description.attributes_fn)
|
||||||
and (fn := self.entity_description.attributes_fn)
|
|
||||||
else super().extra_state_attributes
|
else super().extra_state_attributes
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -122,7 +121,7 @@ class XboxConsoleBaseEntity(CoordinatorEntity[XboxUpdateCoordinator]):
|
|||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, console.id)},
|
identifiers={(DOMAIN, console.id)},
|
||||||
manufacturer="Microsoft",
|
manufacturer="Microsoft",
|
||||||
model=MAP_MODEL.get(self._console.console_type, "Unknown"),
|
model=MAP_MODEL.get(self._console.console_type),
|
||||||
name=console.name,
|
name=console.name,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -135,11 +134,11 @@ class XboxConsoleBaseEntity(CoordinatorEntity[XboxUpdateCoordinator]):
|
|||||||
def check_deprecated_entity(
|
def check_deprecated_entity(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
xuid: str,
|
xuid: str,
|
||||||
entity_description: EntityDescription,
|
entity_description: XboxBaseEntityDescription,
|
||||||
entity_domain: str,
|
entity_domain: str,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Check for deprecated entity and remove it."""
|
"""Check for deprecated entity and remove it."""
|
||||||
if not getattr(entity_description, "deprecated", False):
|
if not entity_description.deprecated:
|
||||||
return True
|
return True
|
||||||
ent_reg = er.async_get(hass)
|
ent_reg = er.async_get(hass)
|
||||||
if entity_id := ent_reg.async_get_entity_id(
|
if entity_id := ent_reg.async_get_entity_id(
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Xbox images."""
|
"""Set up Xbox images."""
|
||||||
|
|
||||||
coordinator = config_entry.runtime_data
|
coordinator = config_entry.runtime_data.status
|
||||||
|
|
||||||
xuids_added: set[str] = set()
|
xuids_added: set[str] = set()
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
"name": "Xbox",
|
"name": "Xbox",
|
||||||
"codeowners": ["@hunterjm", "@tr4nt0r"],
|
"codeowners": ["@hunterjm", "@tr4nt0r"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"dependencies": ["auth", "application_credentials"],
|
"dependencies": ["application_credentials"],
|
||||||
"dhcp": [
|
"dhcp": [
|
||||||
{
|
{
|
||||||
"hostname": "xbox*"
|
"hostname": "xbox*"
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Xbox media_player from a config entry."""
|
"""Set up Xbox media_player from a config entry."""
|
||||||
|
|
||||||
coordinator = entry.runtime_data
|
coordinator = entry.runtime_data.status
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ class XboxSource(MediaSource):
|
|||||||
translation_key="account_not_configured",
|
translation_key="account_not_configured",
|
||||||
) from e
|
) from e
|
||||||
|
|
||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.status.client
|
||||||
|
|
||||||
if identifier.media_type in (ATTR_GAMECLIPS, ATTR_COMMUNITY_GAMECLIPS):
|
if identifier.media_type in (ATTR_GAMECLIPS, ATTR_COMMUNITY_GAMECLIPS):
|
||||||
try:
|
try:
|
||||||
@@ -302,7 +302,7 @@ class XboxSource(MediaSource):
|
|||||||
async def _build_games(self, entry: XboxConfigEntry) -> list[BrowseMediaSource]:
|
async def _build_games(self, entry: XboxConfigEntry) -> list[BrowseMediaSource]:
|
||||||
"""List Xbox games for the selected account."""
|
"""List Xbox games for the selected account."""
|
||||||
|
|
||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.status.client
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
assert entry.unique_id
|
assert entry.unique_id
|
||||||
fields = [
|
fields = [
|
||||||
@@ -346,7 +346,7 @@ class XboxSource(MediaSource):
|
|||||||
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
||||||
) -> BrowseMediaSource:
|
) -> BrowseMediaSource:
|
||||||
"""Display game title."""
|
"""Display game title."""
|
||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.status.client
|
||||||
try:
|
try:
|
||||||
game = (await client.titlehub.get_title_info(identifier.title_id)).titles[0]
|
game = (await client.titlehub.get_title_info(identifier.title_id)).titles[0]
|
||||||
except TimeoutException as e:
|
except TimeoutException as e:
|
||||||
@@ -402,7 +402,7 @@ class XboxSource(MediaSource):
|
|||||||
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
||||||
) -> BrowseMediaSource:
|
) -> BrowseMediaSource:
|
||||||
"""List game media."""
|
"""List game media."""
|
||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.status.client
|
||||||
try:
|
try:
|
||||||
game = (await client.titlehub.get_title_info(identifier.title_id)).titles[0]
|
game = (await client.titlehub.get_title_info(identifier.title_id)).titles[0]
|
||||||
except TimeoutException as e:
|
except TimeoutException as e:
|
||||||
@@ -439,7 +439,7 @@ class XboxSource(MediaSource):
|
|||||||
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
||||||
) -> list[BrowseMediaSource]:
|
) -> list[BrowseMediaSource]:
|
||||||
"""List media items."""
|
"""List media items."""
|
||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.status.client
|
||||||
|
|
||||||
if identifier.media_type != ATTR_GAMECLIPS:
|
if identifier.media_type != ATTR_GAMECLIPS:
|
||||||
return []
|
return []
|
||||||
@@ -483,7 +483,7 @@ class XboxSource(MediaSource):
|
|||||||
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
||||||
) -> list[BrowseMediaSource]:
|
) -> list[BrowseMediaSource]:
|
||||||
"""List media items."""
|
"""List media items."""
|
||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.status.client
|
||||||
|
|
||||||
if identifier.media_type != ATTR_COMMUNITY_GAMECLIPS:
|
if identifier.media_type != ATTR_COMMUNITY_GAMECLIPS:
|
||||||
return []
|
return []
|
||||||
@@ -527,7 +527,7 @@ class XboxSource(MediaSource):
|
|||||||
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
||||||
) -> list[BrowseMediaSource]:
|
) -> list[BrowseMediaSource]:
|
||||||
"""List media items."""
|
"""List media items."""
|
||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.status.client
|
||||||
|
|
||||||
if identifier.media_type != ATTR_SCREENSHOTS:
|
if identifier.media_type != ATTR_SCREENSHOTS:
|
||||||
return []
|
return []
|
||||||
@@ -571,7 +571,7 @@ class XboxSource(MediaSource):
|
|||||||
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
self, entry: XboxConfigEntry, identifier: XboxMediaSourceIdentifier
|
||||||
) -> list[BrowseMediaSource]:
|
) -> list[BrowseMediaSource]:
|
||||||
"""List media items."""
|
"""List media items."""
|
||||||
client = entry.runtime_data.client
|
client = entry.runtime_data.status.client
|
||||||
|
|
||||||
if identifier.media_type != ATTR_COMMUNITY_SCREENSHOTS:
|
if identifier.media_type != ATTR_COMMUNITY_SCREENSHOTS:
|
||||||
return []
|
return []
|
||||||
@@ -640,7 +640,7 @@ class XboxSource(MediaSource):
|
|||||||
|
|
||||||
def gamerpic(config_entry: XboxConfigEntry) -> str | None:
|
def gamerpic(config_entry: XboxConfigEntry) -> str | None:
|
||||||
"""Return gamerpic."""
|
"""Return gamerpic."""
|
||||||
coordinator = config_entry.runtime_data
|
coordinator = config_entry.runtime_data.status
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
assert config_entry.unique_id
|
assert config_entry.unique_id
|
||||||
person = coordinator.data.presence[coordinator.client.xuid]
|
person = coordinator.data.presence[coordinator.client.xuid]
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up Xbox media_player from a config entry."""
|
"""Set up Xbox media_player from a config entry."""
|
||||||
coordinator = entry.runtime_data
|
coordinator = entry.runtime_data.status
|
||||||
|
|
||||||
async_add_entities(
|
async_add_entities(
|
||||||
[XboxRemote(console, coordinator) for console in coordinator.consoles.result]
|
[XboxRemote(console, coordinator) for console in coordinator.consoles.result]
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user