Skip to content

Commit

Permalink
Tweak for readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
eseglem committed Dec 4, 2024
1 parent 897c84e commit 07db53a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions custom_components/wattbox/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,26 @@ async def async_setup_platform(
discovery_info: DiscoveryInfoType,
) -> None:
"""Setup sensor platform."""
name: str = discovery_info[CONF_NAME]
conf_name: str = discovery_info[CONF_NAME]
clean_name = conf_name.replace(" ", "_").lower()
entities: List[Union[WattBoxSensor, IntegrationSensor]] = []

resource: str
for resource in discovery_info[CONF_RESOURCES]:
if (sensor_type := resource.lower()) not in SENSOR_TYPES:
continue
entities.append(WattBoxSensor(hass, name, sensor_type))
entities.append(WattBoxSensor(hass, conf_name, sensor_type))

# TODO: Add a setting for this, default to true?
# Add an IntegrationSensor, so end users don't have to manually configure it.
entities.append(
IntegrationSensor(
integration_method="trapezoidal",
name=f"{name} Total Energy",
name=f"{conf_name} Total Energy",
round_digits=2,
max_sub_interval=timedelta(minutes = 5),
source_entity=f"sensor.{name}_power".replace(' ','_').lower(),
unique_id=f"{name}_total_energy".replace(' ','_').lower(),
max_sub_interval=timedelta(minutes=5),
source_entity=f"sensor.{clean_name}_power",
unique_id=f"{clean_name}_total_energy",
unit_prefix="k",
unit_time=UnitOfTime.HOURS,
)
Expand Down

0 comments on commit 07db53a

Please sign in to comment.