Skip to content

Commit

Permalink
Uniform argument passing
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwolsink committed Oct 28, 2024
1 parent 7b5ec23 commit 91035ef
Showing 1 changed file with 42 additions and 49 deletions.
91 changes: 42 additions & 49 deletions custom_components/enphase_envoy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,16 @@ async def async_setup_entry(
if coordinator.data.get("inverters_production") is not None:
for inverter in coordinator.data["inverters_production"]:
device_name = f"Inverter {inverter}"
entity_name = f"{device_name} {sensor_description.name}"
serial_number = inverter
entities.append(
EnvoyInverterEntity(
sensor_description,
entity_name,
device_name,
serial_number,
serial_number,
coordinator,
config_entry.unique_id,
description=sensor_description,
name=f"{device_name} {sensor_description.name}",
device_name=device_name,
device_serial_number=serial_number,
serial_number=serial_number,
coordinator=coordinator,
parent_device=config_entry.unique_id,
)
)

Expand Down Expand Up @@ -132,25 +131,23 @@ async def async_setup_entry(
if coordinator.data.get("inverters_status") is not None:
for inverter in coordinator.data["inverters_status"].keys():
device_name = f"Inverter {inverter}"
entity_name = f"{device_name} {sensor_description.name}"
serial_number = inverter
entities.append(
EnvoyInverterEntity(
sensor_description,
entity_name,
device_name,
serial_number,
None,
coordinator,
config_entry.unique_id,
description=sensor_description,
name=f"{device_name} {sensor_description.name}",
device_name=device_name,
device_serial_number=serial_number,
serial_number=None,
coordinator=coordinator,
parent_device=config_entry.unique_id,
)
)

elif sensor_description.key == "batteries_software":
if coordinator.data.get("batteries") is not None:
for battery in coordinator.data["batteries"].keys():
device_name = f"Battery {battery}"
entity_name = f"{device_name} {sensor_description.name}"
serial_number = battery
entities.append(
EnvoyBatteryFirmwareEntity(
Expand All @@ -168,32 +165,30 @@ async def async_setup_entry(
if coordinator.data.get("batteries") is not None:
for battery in coordinator.data["batteries"].keys():
device_name = f"Battery {battery}"
entity_name = f"{device_name} {sensor_description.name}"
serial_number = battery
entities.append(
EnvoyBatteryEntity(
sensor_description,
entity_name,
device_name,
serial_number,
None,
coordinator,
config_entry.unique_id,
description=sensor_description,
name=f"{device_name} {sensor_description.name}",
device_name=device_name,
device_serial_number=serial_number,
serial_number=None,
coordinator=coordinator,
parent_device=config_entry.unique_id,
)
)

elif sensor_description.key.startswith("agg_batteries_"):
if coordinator.data.get("batteries") is not None:
entity_name = f"{name} {sensor_description.name}"
entities.append(
CoordinatedEnvoyEntity(
sensor_description,
entity_name,
name,
config_entry.unique_id,
None,
coordinator,
config_entry.data[CONF_HOST],
description=sensor_description,
name=f"{name} {sensor_description.name}",
device_name=name,
device_serial_number=config_entry.unique_id,
serial_number=None,
coordinator=coordinator,
device_host=config_entry.data[CONF_HOST],
)
)

Expand All @@ -202,16 +197,15 @@ async def async_setup_entry(
if data is None:
continue

entity_name = f"{name} {sensor_description.name}"
entities.append(
CoordinatedEnvoyEntity(
sensor_description,
entity_name,
name,
config_entry.unique_id,
None,
coordinator,
config_entry.data[CONF_HOST],
description=sensor_description,
name=f"{name} {sensor_description.name}",
device_name=name,
device_serial_number=config_entry.unique_id,
serial_number=None,
coordinator=coordinator,
device_host=config_entry.data[CONF_HOST],
)
)

Expand All @@ -224,15 +218,14 @@ async def async_setup_entry(
if data is None:
continue

entity_name = f"{name} {sensor_description.name}"
live_entities[sensor_description.key] = CoordinatedEnvoyEntity(
sensor_description,
entity_name,
name,
config_entry.unique_id,
None,
coordinator,
config_entry.data[CONF_HOST],
description=sensor_description,
name=f"{name} {sensor_description.name}",
device_name=name,
device_serial_number=config_entry.unique_id,
serial_number=None,
coordinator=coordinator,
device_host=config_entry.data[CONF_HOST],
)
entities.append(live_entities[sensor_description.key])

Expand Down

0 comments on commit 91035ef

Please sign in to comment.