Skip to content

Commit

Permalink
Update to HA 2202.04 API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed Apr 7, 2022
1 parent 0bdd758 commit 88015d8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Support for Goodwe solar inverters is present as native integration of [Home Ass
This custom component is experimental version with features not (yet) present in standard HA's integration and is intended for users with specific needs and early adopters of new features.
Use at own risk.

### Differences between HACS 0.9.9.0 and HA 2022.2
### Differences between HACS 0.9.9.0 and HA 2022.4

- Integration configuration parameters `Scan iterval`, `Network retry attempts`, `Network request timeout`.
- Synchronize inverter clock button
Expand Down
5 changes: 2 additions & 3 deletions custom_components/goodwe/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from goodwe import Inverter, InverterError

from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
from homeassistant.const import ENTITY_CATEGORY_CONFIG
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity import DeviceInfo, EntityCategory

from .const import DOMAIN, KEY_DEVICE_INFO, KEY_INVERTER

Expand All @@ -17,7 +16,7 @@
key="synchronize_clock",
name="Synchronize inverter clock",
icon="mdi:clock-check-outline",
entity_category=ENTITY_CATEGORY_CONFIG,
entity_category=EntityCategory.CONFIG,
)


Expand Down
5 changes: 3 additions & 2 deletions custom_components/goodwe/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
"name": "GoodWe Inverter",
"documentation": "https://github.com/mletenay/home-assistant-goodwe-inverter",
"issue_tracker": "https://github.com/mletenay/home-assistant-goodwe-inverter/issues",
"codeowners": [
"codeowners": [
"@mletenay",
"@starkillerOG",
"@fizcris"
],
"requirements": ["goodwe==0.2.16"],
"requirements": ["goodwe==0.2.17"],
"config_flow": true,
"iot_class": "local_polling",
"loggers": ["goodwe"],
"version": "1.0.0"
}
10 changes: 5 additions & 5 deletions custom_components/goodwe/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

from homeassistant.components.number import NumberEntity, NumberEntityDescription
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_CONFIG, PERCENTAGE, POWER_WATT
from homeassistant.const import PERCENTAGE, POWER_WATT
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import (
Expand Down Expand Up @@ -51,7 +51,7 @@ async def _set_eco_mode_power(entity: InverterNumberEntity, value: int) -> None:
key="grid_export_limit",
name="Grid export limit",
icon="mdi:transmission-tower",
entity_category=ENTITY_CATEGORY_CONFIG,
entity_category=EntityCategory.CONFIG,
unit_of_measurement=POWER_WATT,
getter=lambda inv: inv.get_grid_export_limit(),
setter=lambda inv, val: inv.inverter.set_grid_export_limit(val),
Expand All @@ -63,7 +63,7 @@ async def _set_eco_mode_power(entity: InverterNumberEntity, value: int) -> None:
key="battery_discharge_depth",
name="Depth of discharge (on-grid)",
icon="mdi:battery-arrow-down",
entity_category=ENTITY_CATEGORY_CONFIG,
entity_category=EntityCategory.CONFIG,
unit_of_measurement=PERCENTAGE,
getter=lambda inv: inv.get_ongrid_battery_dod(),
setter=lambda inv, val: inv.inverter.set_ongrid_battery_dod(val),
Expand All @@ -75,7 +75,7 @@ async def _set_eco_mode_power(entity: InverterNumberEntity, value: int) -> None:
key="eco_mode_power",
name="Eco mode power",
icon="mdi:battery-charging-low",
entity_category=ENTITY_CATEGORY_CONFIG,
entity_category=EntityCategory.CONFIG,
unit_of_measurement=PERCENTAGE,
getter=lambda inv: inv.get_operation_mode(),
setter=_set_eco_mode_power,
Expand Down
14 changes: 10 additions & 4 deletions custom_components/goodwe/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from goodwe import Inverter, InverterError

from homeassistant.components.select import SelectEntity, SelectEntityDescription
from homeassistant.const import ENTITY_CATEGORY_CONFIG
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import (
DOMAIN,
Expand All @@ -31,11 +33,15 @@
key="operation_mode",
name="Inverter operation mode",
icon="mdi:solar-power",
entity_category=ENTITY_CATEGORY_CONFIG,
entity_category=EntityCategory.CONFIG,
)


async def async_setup_entry(hass, config_entry, async_add_entities):
async def async_setup_entry(
hass: HomeAssistant,
config_entry: ConfigEntry,
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the inverter select entities from a config entry."""
domain_data = hass.data[DOMAIN][config_entry.entry_id]
inverter = domain_data[KEY_INVERTER]
Expand Down
45 changes: 19 additions & 26 deletions custom_components/goodwe/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,23 @@
from goodwe import Inverter, Sensor, SensorKind

from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_CURRENT,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_VOLTAGE,
ELECTRIC_CURRENT_AMPERE,
ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR,
ENTITY_CATEGORY_DIAGNOSTIC,
FREQUENCY_HERTZ,
PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
Expand Down Expand Up @@ -75,50 +68,50 @@ class GoodweSensorEntityDescription(SensorEntityDescription):
_DESCRIPTIONS = {
"A": GoodweSensorEntityDescription(
key="A",
device_class=DEVICE_CLASS_CURRENT,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.CURRENT,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
),
"V": GoodweSensorEntityDescription(
key="V",
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
),
"W": GoodweSensorEntityDescription(
key="W",
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=POWER_WATT,
),
"kWh": GoodweSensorEntityDescription(
key="kWh",
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value=lambda sensor, prev, val: prev if "total" in sensor and not val else val,
),
"C": GoodweSensorEntityDescription(
key="C",
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=TEMP_CELSIUS,
),
"Hz": GoodweSensorEntityDescription(
key="Hz",
device_class=DEVICE_CLASS_VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.VOLTAGE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=FREQUENCY_HERTZ,
),
"%": GoodweSensorEntityDescription(
key="%",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
),
}
DIAG_SENSOR = GoodweSensorEntityDescription(
key="_",
state_class=STATE_CLASS_MEASUREMENT,
state_class=SensorStateClass.MEASUREMENT,
)


Expand Down Expand Up @@ -159,15 +152,15 @@ def __init__(
self._attr_unique_id = f"{DOMAIN}-{sensor.id_}-{inverter.serial_number}"
self._attr_device_info = device_info
self._attr_entity_category = (
ENTITY_CATEGORY_DIAGNOSTIC if sensor.id_ not in _MAIN_SENSORS else None
EntityCategory.DIAGNOSTIC if sensor.id_ not in _MAIN_SENSORS else None
)
self.entity_description = _DESCRIPTIONS.get(sensor.unit, DIAG_SENSOR)
if not self.entity_description.native_unit_of_measurement:
self._attr_native_unit_of_measurement = sensor.unit
self._attr_icon = _ICONS.get(sensor.kind)
# Set the inverter SoC as main device battery sensor
if sensor.id_ == BATTERY_SOC:
self._attr_device_class = DEVICE_CLASS_BATTERY
self._attr_device_class = SensorDeviceClass.BATTERY
self._sensor = sensor
self._previous_value = None

Expand Down
4 changes: 2 additions & 2 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "GoodWe Inverter (experimental)",
"country": "SK",
"domains": ["sensor"],
"homeassistant": "2022.2.0"
"domains": ["button", "number", "select", "sensor"],
"homeassistant": "2022.4.0"
}
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Support for Goodwe solar inverters is present as native integration of [Home Ass
This custom component is experimental version with features not (yet) present in standard HA's integration and is intended for users with specific needs and early adopters of new features.
Use at own risk.

### Differences between HACS 0.9.9.0 and HA 2022.2
### Differences between HACS 0.9.9.0 and HA 2022.4

- Integration configuration parameters `Scan iterval`, `Network retry attempts`, `Network request timeout`.
- Synchronize inverter clock button
Expand Down

0 comments on commit 88015d8

Please sign in to comment.