393 files
This commit is contained in:
1 parent
b05b7a897e
commit
39d97ac2db
404 files changed
+54006
-11034
No files matched your search
@@ -24,6 +24,7 @@ from homeassistant.const import (
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
EntityCategory,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
)
|
||||
@@ -59,6 +60,7 @@ from custom_components.powercalc.const import (
|
||||
CONF_CREATE_ENERGY_SENSOR,
|
||||
CONF_CREATE_GROUP,
|
||||
CONF_DISABLE_EXTENDED_ATTRIBUTES,
|
||||
CONF_ENERGY_SENSOR_CATEGORY,
|
||||
CONF_ENERGY_SENSOR_PRECISION,
|
||||
CONF_ENERGY_SENSOR_UNIT_PREFIX,
|
||||
CONF_EXCLUDE_ENTITIES,
|
||||
@@ -75,6 +77,7 @@ from custom_components.powercalc.const import (
|
||||
CONF_HIDE_MEMBERS,
|
||||
CONF_IGNORE_UNAVAILABLE_STATE,
|
||||
CONF_INCLUDE_NON_POWERCALC_SENSORS,
|
||||
CONF_POWER_SENSOR_CATEGORY,
|
||||
CONF_POWER_SENSOR_PRECISION,
|
||||
CONF_SENSOR_TYPE,
|
||||
CONF_SUB_GROUPS,
|
||||
@@ -428,6 +431,7 @@ def create_grouped_energy_sensor(
|
||||
name=name,
|
||||
unique_id=energy_unique_id,
|
||||
sensor_config=sensor_config,
|
||||
entity_category=sensor_config.get(CONF_ENERGY_SENSOR_CATEGORY),
|
||||
unit_prefix=sensor_config.get(CONF_ENERGY_SENSOR_UNIT_PREFIX, UnitPrefix.NONE),
|
||||
)
|
||||
|
||||
@@ -484,6 +488,10 @@ class GroupedSensor(BaseEntity, SensorEntity):
|
||||
sensor_config.get(CONF_GROUP_POWER_UPDATE_INTERVAL, DEFAULT_GROUP_POWER_UPDATE_INTERVAL),
|
||||
)
|
||||
self._attr_suggested_display_precision = self._rounding_digits
|
||||
category_key = CONF_ENERGY_SENSOR_CATEGORY if self._is_energy_sensor else CONF_POWER_SENSOR_CATEGORY
|
||||
entity_category = sensor_config.get(category_key)
|
||||
if entity_category:
|
||||
self._attr_entity_category = EntityCategory(entity_category)
|
||||
if unique_id:
|
||||
self._attr_unique_id = unique_id
|
||||
self._native_value_exact = Decimal(0)
|
||||
|
||||
@@ -7,7 +7,7 @@ from homeassistant.components.sensor import (
|
||||
SensorEntity,
|
||||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, CONF_NAME, UnitOfPower
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, CONF_NAME, EntityCategory, UnitOfPower
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity import Entity
|
||||
@@ -18,6 +18,7 @@ from custom_components.powercalc.const import (
|
||||
ATTR_MEMBERS,
|
||||
ATTR_STATE,
|
||||
CONF_CREATE_ENERGY_SENSORS,
|
||||
CONF_POWER_SENSOR_CATEGORY,
|
||||
CONF_POWER_SENSOR_PRECISION,
|
||||
DATA_STANDBY_POWER_SENSORS,
|
||||
DEFAULT_POWER_SENSOR_PRECISION,
|
||||
@@ -40,6 +41,7 @@ def create_general_standby_sensors(
|
||||
power_sensor = StandbyPowerSensor(
|
||||
hass,
|
||||
rounding_digits=int(config.get(CONF_POWER_SENSOR_PRECISION, DEFAULT_POWER_SENSOR_PRECISION)),
|
||||
entity_category=config.get(CONF_POWER_SENSOR_CATEGORY),
|
||||
)
|
||||
sensors.append(power_sensor)
|
||||
if config.get(CONF_CREATE_ENERGY_SENSORS):
|
||||
@@ -66,9 +68,16 @@ class StandbyPowerSensor(PowerSensor, SensorEntity):
|
||||
_attr_unique_id = "powercalc_standby_group"
|
||||
_attr_name = "All standby power"
|
||||
|
||||
def __init__(self, hass: HomeAssistant, rounding_digits: int = 2) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
hass: HomeAssistant,
|
||||
rounding_digits: int = 2,
|
||||
entity_category: str | None = None,
|
||||
) -> None:
|
||||
self.standby_sensors: dict[str, Decimal] = hass.data[DOMAIN][DATA_STANDBY_POWER_SENSORS]
|
||||
self._rounding_digits = rounding_digits
|
||||
if entity_category:
|
||||
self._attr_entity_category = EntityCategory(entity_category)
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Register state listeners."""
|
||||
|
||||
Reference in new issue
Block a user