Skip to content

Commit 160554e

Browse files
Merge pull request #67 from vincentwolsink/random-fixes
Random fixes and updates
2 parents d7a136c + 74f9f0d commit 160554e

File tree

4 files changed

+113
-159
lines changed

4 files changed

+113
-159
lines changed

custom_components/enphase_envoy/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ async def _async_stop(_: Event) -> None:
187187
_LOGGER.debug("Stopping loop for /stream/meter")
188188
task.cancel()
189189

190+
hass.data[DOMAIN][entry.entry_id]["realtime_loop"] = False
191+
190192
# Make sure task is cancelled on shutdown (or tests complete)
191193
entry.async_on_unload(
192194
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_stop)
@@ -202,11 +204,13 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
202204

203205
if task := hass.data[DOMAIN][entry.entry_id].get("realtime_loop", False):
204206
_LOGGER.debug("Stopping loop for /stream/meter")
205-
task.cancel()
206207

207208
with suppress(asyncio.CancelledError):
209+
task.cancel()
208210
await task
209211

212+
hass.data[DOMAIN][entry.entry_id]["realtime_loop"] = False
213+
210214
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
211215
if unload_ok:
212216
hass.data[DOMAIN].pop(entry.entry_id)

custom_components/enphase_envoy/binary_sensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def async_setup_entry(
8989
)
9090

9191
elif sensor_description.key == "firmware":
92-
if coordinator.data.get("update_status") is not None:
92+
if coordinator.data.get("envoy_info", {}).get("update_status") is not None:
9393
entity_name = f"{name} {sensor_description.name}"
9494
serial_number = name.split(None, 1)[-1]
9595
entities.append(

custom_components/enphase_envoy/const.py

Lines changed: 69 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,39 @@
5050
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
5151
state_class=SensorStateClass.TOTAL_INCREASING,
5252
device_class=SensorDeviceClass.ENERGY,
53+
suggested_display_precision=0,
5354
),
5455
SensorEntityDescription(
5556
key="lifetime_production",
5657
name="Lifetime Energy Production",
5758
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
5859
state_class=SensorStateClass.TOTAL_INCREASING,
5960
device_class=SensorDeviceClass.ENERGY,
61+
suggested_display_precision=0,
6062
),
6163
SensorEntityDescription(
6264
key="consumption",
6365
name="Current Power Consumption",
6466
native_unit_of_measurement=UnitOfPower.WATT,
6567
state_class=SensorStateClass.MEASUREMENT,
6668
device_class=SensorDeviceClass.POWER,
69+
suggested_display_precision=0,
6770
),
6871
SensorEntityDescription(
6972
key="daily_consumption",
7073
name="Today's Energy Consumption",
7174
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
7275
state_class=SensorStateClass.TOTAL_INCREASING,
7376
device_class=SensorDeviceClass.ENERGY,
77+
suggested_display_precision=0,
7478
),
7579
SensorEntityDescription(
7680
key="lifetime_consumption",
7781
name="Lifetime Energy Consumption",
7882
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
7983
state_class=SensorStateClass.TOTAL_INCREASING,
8084
device_class=SensorDeviceClass.ENERGY,
85+
suggested_display_precision=0,
8186
),
8287
SensorEntityDescription(
8388
key="inverters",
@@ -146,155 +151,70 @@
146151
),
147152
)
148153

149-
PHASE_SENSORS = (
150-
SensorEntityDescription(
151-
key="production_l1",
152-
name="Current Power Production L1",
153-
native_unit_of_measurement=UnitOfPower.WATT,
154-
state_class=SensorStateClass.MEASUREMENT,
155-
device_class=SensorDeviceClass.POWER,
156-
),
157-
SensorEntityDescription(
158-
key="daily_production_l1",
159-
name="Today's Energy Production L1",
160-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
161-
state_class=SensorStateClass.TOTAL_INCREASING,
162-
device_class=SensorDeviceClass.ENERGY,
163-
),
164-
SensorEntityDescription(
165-
key="lifetime_production_l1",
166-
name="Lifetime Energy Production L1",
167-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
168-
state_class=SensorStateClass.TOTAL_INCREASING,
169-
device_class=SensorDeviceClass.ENERGY,
170-
),
171-
SensorEntityDescription(
172-
key="voltage_l1",
173-
name="Current Voltage L1",
174-
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
175-
state_class=SensorStateClass.MEASUREMENT,
176-
device_class=SensorDeviceClass.VOLTAGE,
177-
),
178-
SensorEntityDescription(
179-
key="production_l2",
180-
name="Current Power Production L2",
181-
native_unit_of_measurement=UnitOfPower.WATT,
182-
state_class=SensorStateClass.MEASUREMENT,
183-
device_class=SensorDeviceClass.POWER,
184-
),
185-
SensorEntityDescription(
186-
key="daily_production_l2",
187-
name="Today's Energy Production L2",
188-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
189-
state_class=SensorStateClass.TOTAL_INCREASING,
190-
device_class=SensorDeviceClass.ENERGY,
191-
),
192-
SensorEntityDescription(
193-
key="lifetime_production_l2",
194-
name="Lifetime Energy Production L2",
195-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
196-
state_class=SensorStateClass.TOTAL_INCREASING,
197-
device_class=SensorDeviceClass.ENERGY,
198-
),
199-
SensorEntityDescription(
200-
key="voltage_l2",
201-
name="Current Voltage L2",
202-
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
203-
state_class=SensorStateClass.MEASUREMENT,
204-
device_class=SensorDeviceClass.VOLTAGE,
205-
),
206-
SensorEntityDescription(
207-
key="production_l3",
208-
name="Current Power Production L3",
209-
native_unit_of_measurement=UnitOfPower.WATT,
210-
state_class=SensorStateClass.MEASUREMENT,
211-
device_class=SensorDeviceClass.POWER,
212-
),
213-
SensorEntityDescription(
214-
key="daily_production_l3",
215-
name="Today's Energy Production L3",
216-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
217-
state_class=SensorStateClass.TOTAL_INCREASING,
218-
device_class=SensorDeviceClass.ENERGY,
219-
),
220-
SensorEntityDescription(
221-
key="lifetime_production_l3",
222-
name="Lifetime Energy Production L3",
223-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
224-
state_class=SensorStateClass.TOTAL_INCREASING,
225-
device_class=SensorDeviceClass.ENERGY,
226-
),
227-
SensorEntityDescription(
228-
key="voltage_l3",
229-
name="Current Voltage L3",
230-
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
231-
state_class=SensorStateClass.MEASUREMENT,
232-
device_class=SensorDeviceClass.VOLTAGE,
233-
),
234-
SensorEntityDescription(
235-
key="consumption_l1",
236-
name="Current Power Consumption L1",
237-
native_unit_of_measurement=UnitOfPower.WATT,
238-
state_class=SensorStateClass.MEASUREMENT,
239-
device_class=SensorDeviceClass.POWER,
240-
),
241-
SensorEntityDescription(
242-
key="daily_consumption_l1",
243-
name="Today's Energy Consumption L1",
244-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
245-
state_class=SensorStateClass.TOTAL_INCREASING,
246-
device_class=SensorDeviceClass.ENERGY,
247-
),
248-
SensorEntityDescription(
249-
key="lifetime_consumption_l1",
250-
name="Lifetime Energy Consumption L1",
251-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
252-
state_class=SensorStateClass.TOTAL_INCREASING,
253-
device_class=SensorDeviceClass.ENERGY,
254-
),
255-
SensorEntityDescription(
256-
key="consumption_l2",
257-
name="Current Power Consumption L2",
258-
native_unit_of_measurement=UnitOfPower.WATT,
259-
state_class=SensorStateClass.MEASUREMENT,
260-
device_class=SensorDeviceClass.POWER,
261-
),
262-
SensorEntityDescription(
263-
key="daily_consumption_l2",
264-
name="Today's Energy Consumption L2",
265-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
266-
state_class=SensorStateClass.TOTAL_INCREASING,
267-
device_class=SensorDeviceClass.ENERGY,
268-
),
269-
SensorEntityDescription(
270-
key="lifetime_consumption_l2",
271-
name="Lifetime Energy Consumption L2",
272-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
273-
state_class=SensorStateClass.TOTAL_INCREASING,
274-
device_class=SensorDeviceClass.ENERGY,
275-
),
276-
SensorEntityDescription(
277-
key="consumption_l3",
278-
name="Current Power Consumption L3",
279-
native_unit_of_measurement=UnitOfPower.WATT,
280-
state_class=SensorStateClass.MEASUREMENT,
281-
device_class=SensorDeviceClass.POWER,
282-
),
283-
SensorEntityDescription(
284-
key="daily_consumption_l3",
285-
name="Today's Energy Consumption L3",
286-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
287-
state_class=SensorStateClass.TOTAL_INCREASING,
288-
device_class=SensorDeviceClass.ENERGY,
289-
),
290-
SensorEntityDescription(
291-
key="lifetime_consumption_l3",
292-
name="Lifetime Energy Consumption L3",
293-
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
294-
state_class=SensorStateClass.TOTAL_INCREASING,
295-
device_class=SensorDeviceClass.ENERGY,
296-
),
297-
)
154+
PHASE_SENSORS = []
155+
for phase in ["l1", "l2", "l3"]:
156+
PHASE_SENSORS.extend(
157+
[
158+
SensorEntityDescription(
159+
key=f"production_{phase}",
160+
name=f"Current Power Production {phase.upper()}",
161+
native_unit_of_measurement=UnitOfPower.WATT,
162+
state_class=SensorStateClass.MEASUREMENT,
163+
device_class=SensorDeviceClass.POWER,
164+
suggested_display_precision=0,
165+
),
166+
SensorEntityDescription(
167+
key=f"daily_production_{phase}",
168+
name=f"Today's Energy Production {phase.upper()}",
169+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
170+
state_class=SensorStateClass.TOTAL_INCREASING,
171+
device_class=SensorDeviceClass.ENERGY,
172+
suggested_display_precision=0,
173+
),
174+
SensorEntityDescription(
175+
key=f"lifetime_production_{phase}",
176+
name=f"Lifetime Energy Production {phase.upper()}",
177+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
178+
state_class=SensorStateClass.TOTAL_INCREASING,
179+
device_class=SensorDeviceClass.ENERGY,
180+
suggested_display_precision=0,
181+
),
182+
SensorEntityDescription(
183+
key=f"voltage_{phase}",
184+
name=f"Current Voltage {phase.upper()}",
185+
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
186+
state_class=SensorStateClass.MEASUREMENT,
187+
device_class=SensorDeviceClass.VOLTAGE,
188+
),
189+
#
190+
# Consumption entities
191+
#
192+
SensorEntityDescription(
193+
key=f"consumption_{phase}",
194+
name=f"Current Power Consumption {phase.upper()}",
195+
native_unit_of_measurement=UnitOfPower.WATT,
196+
state_class=SensorStateClass.MEASUREMENT,
197+
device_class=SensorDeviceClass.POWER,
198+
suggested_display_precision=0,
199+
),
200+
SensorEntityDescription(
201+
key=f"daily_consumption_{phase}",
202+
name=f"Today's Energy Consumption {phase.upper()}",
203+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
204+
state_class=SensorStateClass.TOTAL_INCREASING,
205+
device_class=SensorDeviceClass.ENERGY,
206+
suggested_display_precision=0,
207+
),
208+
SensorEntityDescription(
209+
key=f"lifetime_consumption_{phase}",
210+
name=f"Lifetime Energy Consumption {phase.upper()}",
211+
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
212+
state_class=SensorStateClass.TOTAL_INCREASING,
213+
device_class=SensorDeviceClass.ENERGY,
214+
suggested_display_precision=0,
215+
),
216+
]
217+
)
298218

299219
BINARY_SENSORS = (
300220
BinarySensorEntityDescription(

0 commit comments

Comments
 (0)