Skip to content

Commit

Permalink
Add Sensors for HomeWizard Plug-In Battery
Browse files Browse the repository at this point in the history
  • Loading branch information
DCSBL committed Jan 13, 2025
1 parent fc6695b commit 7f60d0b
Show file tree
Hide file tree
Showing 9 changed files with 1,002 additions and 0 deletions.
3 changes: 3 additions & 0 deletions homeassistant/components/homewizard/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
"any_power_fail_count": {
"default": "mdi:transmission-tower-off"
},
"cycles": {
"default": "mdi:number_of_charging_cycles"
},
"dsmr_version": {
"default": "mdi:counter"
},
Expand Down
18 changes: 18 additions & 0 deletions homeassistant/components/homewizard/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,24 @@ def to_percentage(value: float | None) -> float | None:
has_fn=lambda data: data.total_liter_m3 is not None,
value_fn=lambda data: data.total_liter_m3,
),
HomeWizardSensorEntityDescription(
key="state_of_charge_pct",
translation_key="state_of_charge_pct",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY,
state_class=SensorStateClass.MEASUREMENT,
has_fn=lambda data: data.state_of_charge_pct is not None,
value_fn=lambda data: data.state_of_charge_pct,
),
HomeWizardSensorEntityDescription(
key="cycles",
translation_key="cycles",
entity_category=EntityCategory.DIAGNOSTIC,
state_class=SensorStateClass.TOTAL,
icon="mdi:battery-sync-outline",
has_fn=lambda data: data.cycles is not None,
value_fn=lambda data: data.cycles,
),
)


Expand Down
6 changes: 6 additions & 0 deletions homeassistant/components/homewizard/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@
},
"total_liter_m3": {
"name": "Total water usage"
},
"cycles": {
"name": "Battery cycles"
},
"state_of_charge_pct": {
"name": "State of charge"
}
},
"switch": {
Expand Down
12 changes: 12 additions & 0 deletions tests/components/homewizard/fixtures/HWE-BAT/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"wifi_ssid": "simulating v1 support",
"wifi_strength": 100,
"total_power_import_kwh": 123.456,
"total_power_export_kwh": 123.456,
"active_power_w": 123,
"active_voltage_v": 230,
"active_current_a": 1.5,
"active_frequency_hz": 50,
"state_of_charge_pct": 50,
"cycles": 123
}
7 changes: 7 additions & 0 deletions tests/components/homewizard/fixtures/HWE-BAT/device.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"product_type": "HWE-BAT",
"product_name": "Plug-In Battery",
"serial": "5c2fafabcdef",
"firmware_version": "1.00",
"api_version": "v1"
}
90 changes: 90 additions & 0 deletions tests/components/homewizard/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
@@ -1,4 +1,94 @@
# serializer version: 1
# name: test_diagnostics[HWE-BAT]
dict({
'data': dict({
'device': dict({
'api_version': 'v1',
'firmware_version': '1.00',
'id': '**REDACTED**',
'model_name': 'Plug-In Battery',
'product_name': 'Plug-In Battery',
'product_type': 'HWE-BAT',
'serial': '**REDACTED**',
}),
'measurement': dict({
'active_liter_lpm': None,
'any_power_fail_count': None,
'apparent_power_l1_va': None,
'apparent_power_l2_va': None,
'apparent_power_l3_va': None,
'apparent_power_va': None,
'average_power_15m_w': None,
'current_a': 1.5,
'current_l1_a': None,
'current_l2_a': None,
'current_l3_a': None,
'cycles': 123,
'energy_export_kwh': 123.456,
'energy_export_t1_kwh': None,
'energy_export_t2_kwh': None,
'energy_export_t3_kwh': None,
'energy_export_t4_kwh': None,
'energy_import_kwh': 123.456,
'energy_import_t1_kwh': None,
'energy_import_t2_kwh': None,
'energy_import_t3_kwh': None,
'energy_import_t4_kwh': None,
'external_devices': None,
'frequency_hz': 50.0,
'long_power_fail_count': None,
'meter_model': None,
'monthly_power_peak_timestamp': None,
'monthly_power_peak_w': None,
'power_factor': None,
'power_factor_l1': None,
'power_factor_l2': None,
'power_factor_l3': None,
'power_l1_w': None,
'power_l2_w': None,
'power_l3_w': None,
'power_w': 123.0,
'protocol_version': None,
'reactive_power_l1_var': None,
'reactive_power_l2_var': None,
'reactive_power_l3_var': None,
'reactive_power_var': None,
'state_of_charge_pct': 50.0,
'tariff': None,
'timestamp': None,
'total_liter_m3': None,
'unique_id': None,
'voltage_l1_v': None,
'voltage_l2_v': None,
'voltage_l3_v': None,
'voltage_sag_l1_count': None,
'voltage_sag_l2_count': None,
'voltage_sag_l3_count': None,
'voltage_swell_l1_count': None,
'voltage_swell_l2_count': None,
'voltage_swell_l3_count': None,
'voltage_v': 230.0,
'wifi_ssid': '**REDACTED**',
'wifi_strength': 100,
}),
'state': None,
'system': dict({
'api_v1_enabled': None,
'cloud_enabled': None,
'status_led_brightness_pct': None,
'uptime_s': None,
'wifi_rssi_db': None,
'wifi_ssid': '**REDACTED**',
}),
}),
'entry': dict({
'ip_address': '**REDACTED**',
'product_name': 'P1 Meter',
'product_type': 'HWE-P1',
'serial': '**REDACTED**',
}),
})
# ---
# name: test_diagnostics[HWE-KWH1]
dict({
'data': dict({
Expand Down
Loading

0 comments on commit 7f60d0b

Please sign in to comment.