Skip to content

Commit

Permalink
Merge 984357b into 50529a5
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Jul 30, 2022
2 parents 50529a5 + 984357b commit e452cf8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ All these settings are completely optional. You can skip this section if you don
| Name | Type | Requirement | Default | Description |
| ----------------------------- | ------- | ------------ | ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| enable_autodiscovery | boolean | **Optional** | true | Whether you want powercalc to automatically setup power sensors for supported models in your HA instance.
| scan_interval | string | **Optional** | 00:10:00 | Interval at which the sensor state is updated, even when the power value stays the same. Format HH:MM:SS |
| force_update_frequency | string | **Optional** | 00:10:00 | Interval at which the sensor state is updated, even when the power value stays the same. Format HH:MM:SS |
| create_energy_sensors | boolean | **Optional** | true | Let the component automatically create energy sensors (kWh) for every power sensor |
| power_sensor_naming | string | **Optional** | {} power | Change the name of the sensors. Use the `{}` placeholder for the entity name of your appliance. This will also change the entity_id of your sensor |
| power_sensor_friendly_naming | string | **Optional** | | Change the friendly name of the sensors, Use `{}` placehorder for the original entity name. |
Expand Down
8 changes: 5 additions & 3 deletions custom_components/powercalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
CONF_ENERGY_SENSOR_NAMING,
CONF_ENERGY_SENSOR_PRECISION,
CONF_ENERGY_SENSOR_UNIT_PREFIX,
CONF_FORCE_UPDATE_FREQUENCY,
CONF_POWER_SENSOR_CATEGORY,
CONF_POWER_SENSOR_FRIENDLY_NAMING,
CONF_POWER_SENSOR_NAMING,
Expand All @@ -56,7 +57,7 @@
DEFAULT_ENTITY_CATEGORY,
DEFAULT_POWER_NAME_PATTERN,
DEFAULT_POWER_SENSOR_PRECISION,
DEFAULT_SCAN_INTERVAL,
DEFAULT_UPDATE_FREQUENCY,
DEFAULT_UTILITY_METER_TYPES,
DISCOVERY_LIGHT_MODEL,
DISCOVERY_SOURCE_ENTITY,
Expand All @@ -80,10 +81,11 @@
CONFIG_SCHEMA = vol.Schema(
{
DOMAIN: vol.All(
cv.deprecated(CONF_SCAN_INTERVAL, replacement_key=CONF_FORCE_UPDATE_FREQUENCY),
vol.Schema(
{
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
CONF_FORCE_UPDATE_FREQUENCY, default=DEFAULT_UPDATE_FREQUENCY
): cv.time_period,
vol.Optional(
CONF_POWER_SENSOR_NAMING, default=DEFAULT_POWER_NAME_PATTERN
Expand Down Expand Up @@ -160,7 +162,7 @@ async def async_setup(hass: HomeAssistant, config: dict) -> bool:
CONF_ENERGY_SENSOR_PRECISION: DEFAULT_ENERGY_SENSOR_PRECISION,
CONF_ENERGY_SENSOR_CATEGORY: DEFAULT_ENTITY_CATEGORY,
CONF_ENERGY_SENSOR_UNIT_PREFIX: UnitPrefix.KILO,
CONF_SCAN_INTERVAL: DEFAULT_SCAN_INTERVAL,
CONF_FORCE_UPDATE_FREQUENCY: DEFAULT_UPDATE_FREQUENCY,
CONF_CREATE_DOMAIN_GROUPS: [],
CONF_CREATE_ENERGY_SENSORS: True,
CONF_CREATE_UTILITY_METERS: False,
Expand Down
3 changes: 2 additions & 1 deletion custom_components/powercalc/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
CONF_ENERGY_SENSOR_PRECISION = "energy_sensor_precision"
CONF_ENERGY_SENSOR_UNIT_PREFIX = "energy_sensor_unit_prefix"
CONF_FIXED = "fixed"
CONF_FORCE_UPDATE_FREQUENCY = "force_update_frequency"
CONF_GROUP = "group"
CONF_GROUP_POWER_ENTITIES = "group_power_entities"
CONF_GROUP_ENERGY_ENTITIES = "group_energy_entities"
Expand Down Expand Up @@ -113,7 +114,7 @@ class UnitPrefix(StrEnum):
ENTITY_CATEGORY_SYSTEM,
]

DEFAULT_SCAN_INTERVAL = timedelta(minutes=10)
DEFAULT_UPDATE_FREQUENCY = timedelta(minutes=10)
DEFAULT_POWER_NAME_PATTERN = "{} power"
DEFAULT_POWER_SENSOR_PRECISION = 2
DEFAULT_ENERGY_INTEGRATION_METHOD = ENERGY_INTEGRATION_METHOD_TRAPEZODIAL
Expand Down
10 changes: 5 additions & 5 deletions custom_components/powercalc/sensors/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
)
from homeassistant.const import (
CONF_NAME,
CONF_SCAN_INTERVAL,
CONF_UNIQUE_ID,
POWER_WATT,
STATE_ON,
Expand Down Expand Up @@ -52,6 +51,7 @@
CONF_POWER_SENSOR_ID,
CONF_POWER_SENSOR_PRECISION,
CONF_STANDBY_POWER,
CONF_FORCE_UPDATE_FREQUENCY,
CONF_WLED,
DATA_CALCULATOR_FACTORY,
DISCOVERY_LIGHT_MODEL,
Expand Down Expand Up @@ -200,7 +200,7 @@ async def create_virtual_power_sensor(
unique_id=unique_id,
standby_power=standby_power,
standby_power_on=standby_power_on,
scan_interval=sensor_config.get(CONF_SCAN_INTERVAL),
update_frequency=sensor_config.get(CONF_FORCE_UPDATE_FREQUENCY),
multiply_factor=sensor_config.get(CONF_MULTIPLY_FACTOR),
multiply_factor_standby=sensor_config.get(CONF_MULTIPLY_FACTOR_STANDBY),
ignore_unavailable_state=sensor_config.get(CONF_IGNORE_UNAVAILABLE_STATE),
Expand Down Expand Up @@ -283,7 +283,7 @@ def __init__(
unique_id: str,
standby_power: Decimal,
standby_power_on: Decimal,
scan_interval,
update_frequency,
multiply_factor: float | None,
multiply_factor_standby: bool,
ignore_unavailable_state: bool,
Expand All @@ -301,7 +301,7 @@ def __init__(
self._standby_power_on = standby_power_on
self._attr_force_update = True
self._attr_unique_id = unique_id
self._scan_interval = scan_interval
self._update_frequency = update_frequency
self._multiply_factor = multiply_factor
self._multiply_factor_standby = multiply_factor_standby
self._ignore_unavailable_state = ignore_unavailable_state
Expand Down Expand Up @@ -370,7 +370,7 @@ def async_update(event_time=None):
"""Update the entity."""
self.async_schedule_update_ha_state(True)

async_track_time_interval(self.hass, async_update, self._scan_interval)
async_track_time_interval(self.hass, async_update, self._update_frequency)

async def _update_power_sensor(
self, trigger_entity_id: str, state: State | None
Expand Down

0 comments on commit e452cf8

Please sign in to comment.