217 files
This commit is contained in:
@@ -31,7 +31,7 @@ from homeassistant.core import (
|
||||
State,
|
||||
callback,
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.exceptions import ServiceValidationError
|
||||
from homeassistant.helpers import issue_registry as ir, start
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.entity import EntityCategory
|
||||
@@ -118,7 +118,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
async def create_power_sensor(
|
||||
hass: HomeAssistant,
|
||||
sensor_config: dict,
|
||||
sensor_config: ConfigType,
|
||||
source_entity: SourceEntity,
|
||||
config_entry: ConfigEntry | None,
|
||||
) -> PowerSensor:
|
||||
@@ -326,7 +326,7 @@ def _get_standby_power(
|
||||
|
||||
def create_real_power_sensor(
|
||||
hass: HomeAssistant,
|
||||
sensor_config: dict,
|
||||
sensor_config: ConfigType,
|
||||
) -> RealPowerSensor:
|
||||
"""Create reference to an existing power sensor."""
|
||||
power_sensor_id = sensor_config.get(CONF_POWER_SENSOR_ID)
|
||||
@@ -389,7 +389,7 @@ class VirtualPowerSensor(PowerSensor, SensorEntity):
|
||||
unique_id: str | None,
|
||||
standby_power: Decimal | Template,
|
||||
standby_power_on: Decimal,
|
||||
sensor_config: dict,
|
||||
sensor_config: ConfigType,
|
||||
power_profile: PowerProfile | None,
|
||||
config_entry: ConfigEntry | None,
|
||||
) -> None:
|
||||
@@ -426,7 +426,7 @@ class VirtualPowerSensor(PowerSensor, SensorEntity):
|
||||
self._sub_profile_selector: SubProfileSelector | None = None
|
||||
if not self._ignore_unavailable_state and self._sensor_config.get(CONF_UNAVAILABLE_POWER) is not None:
|
||||
self._ignore_unavailable_state = True
|
||||
self._standby_sensors: dict = hass.data[DOMAIN][DATA_STANDBY_POWER_SENSORS]
|
||||
self._standby_sensors: ConfigType = hass.data[DOMAIN][DATA_STANDBY_POWER_SENSORS]
|
||||
self.calculation_strategy_factory = calculation_strategy_factory
|
||||
self._strategy_instance: PowerCalculationStrategyInterface | None = None
|
||||
self._availability_entity: str | None = sensor_config.get(CONF_AVAILABILITY_ENTITY)
|
||||
@@ -828,7 +828,11 @@ class VirtualPowerSensor(PowerSensor, SensorEntity):
|
||||
"""Ensure we are dealing with a playbook sensor."""
|
||||
assert self._strategy_instance is not None
|
||||
if not isinstance(self._strategy_instance, PlaybookStrategy):
|
||||
raise HomeAssistantError("supported only playbook enabled sensors")
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="not_a_playbook_sensor",
|
||||
translation_placeholders={"entity_id": self.entity_id},
|
||||
)
|
||||
return self._strategy_instance
|
||||
|
||||
async def async_will_remove_from_hass(self) -> None:
|
||||
@@ -847,13 +851,22 @@ class VirtualPowerSensor(PowerSensor, SensorEntity):
|
||||
or not await self._power_profile.has_sub_profiles
|
||||
or self._power_profile.sub_profile_select
|
||||
):
|
||||
raise HomeAssistantError(
|
||||
"This is only supported for sensors having sub profiles, and no automatic profile selection",
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="no_sub_profile_support",
|
||||
translation_placeholders={"entity_id": self.entity_id},
|
||||
)
|
||||
|
||||
known_profiles = [profile[0] for profile in await self._power_profile.get_sub_profiles()]
|
||||
if profile not in known_profiles:
|
||||
raise HomeAssistantError(f"{profile} is not a possible sub profile")
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="unknown_sub_profile",
|
||||
translation_placeholders={
|
||||
"profile": profile,
|
||||
"known_profiles": ", ".join(known_profiles),
|
||||
},
|
||||
)
|
||||
|
||||
await self._select_new_sub_profile(profile)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user