diff --git a/README.md b/README.md
index c14065d..780a937 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,23 @@
-> ⚠️ This integration is available in Core. This custom integration won't be maintained and eventually removed. Click here to install the core integration: https://home-assistant.io/integrations/homewizard/
+> ⚠️ **Make a back-up before installing this version. Your configuration will be migrated to Home Assistant Core.**
# HomeWizard Energy Integration
Custom integration for the [HomeWizard Energy Products](https://www.homewizard.nl/energie).
-## Use the official integration
-**⚠️ Since [Home Assistant 2022.2](https://home-assistant.io/blog/2022/02/02/release-20222/) this integration is available in core! Click [here](https://home-assistant.io/integrations/homewizard/) for more info**
-
+## Integration added to core :tada:
+This integration is available in Core. This custom integration won't be maintained and eventually removed. Click here to read more and install the core integration: https://home-assistant.io/integrations/homewizard/
-I highly recommend to convert your configuration to use the core integration. This custom integration won't be updated from now on.
+# Migration
+**This integration is not maintained and will be removed**
+
+From version [0.13.0](https://github.com/DCSBL/ha-homewizard-energy/releases), this custom integration only exists to allow migration of current configurations.
+If you had a pre-0.13.0 version in use and you install this version, it will automaticly migrate to core.
-1. **Can I transfer my data to the core integration?**
-No. I've spend a couple of hours to try this but it is not possible for now. I will keep an eye on this and will write a migrator when this is possible. You can keep using this custom component.
-Give a thumps up or something to [this issue](https://github.com/DCSBL/ha-homewizard-energy/issues/74) so I can determine the priority.
-2. **My devices are rediscovered**
-This is the core integration that can't see that you already have the same device configured via this custom integration. You can ignore the discovered device.
-3. **What if I have any problems with the integration?**
+## FAQ
+1. **What if I have any problems with the integration?**
If the issues is with the core integration, you can open an issue [here](https://github.com/home-assistant/core/issues/new?assignees=&labels=&template=bug_report.yml). If you have an issue with the custom integration, you can open an issue [here](https://github.com/DCSBL/ha-homewizard-energy/issues)
-4. **Where is `gas_timestamp` and `meter_model`?**
+2. **Where is `gas_timestamp` and `meter_model`?**
Meter model is renamed to `Smart Meter Model`. Gas timestamp is removed because it is the same as 'last updated total gas'. You can get it back with a template sensor:
```
# configuration.yaml
@@ -30,65 +29,4 @@ sensor:
device_class: timestamp
value_template: "{{ as_timestamp(states.sensor.p1_meter__active_power.last_updated) }}"
```
-Replace `p1_meter__total_gas` to use the correct entity id. Now you can use `sensor. p1_meter_gas_timestamp`
-
-5. **I don't care about the data, I just want to use the core integration. How do I migrate?**
-
-**Follow these steps:**
-1. Remove the integration from your configuration. This step is important, otherwise you will get errors like `Setup failed for homewizard_energy: Integration not found`
-
-
-
-2. Remove the integration via HACS or remove the `config/custom_components/homewizard_energy` folder
-3. Restart Home Assistant
-4. Start the normal configuration [Click here](https://my.home-assistant.io/redirect/config_flow_start?domain=homewizard)
-
-## Still wan't to install the custom integration?
-### Requirements
-* This integration works with:
- * [HomeWizard wifi P1 meter](https://www.homewizard.nl/p1-meter)
- * [HomeWizard wifi kWh meter single phase](https://www.homewizard.nl/kwh-meter)
- * [HomeWizard wifi kWh meter 3-phase](https://www.homewizard.nl/kwh-meter)
- * [HomeWizard wifi Energy Socket](https://www.homewizard.nl/energy-socket)
-* Make sure the HomeWizard Energy device has been connected to the same network.
-
-### Installation
-#### HACS (https://hacs.xyz)
-1. Install this integration from HACS (Search for 'HomeWizard Energy').
-2. ❗ **Restart Home Assistant**.
-
-#### Manual installation
-1. Download the zip `homewizard_energy.zip` from the [latest release](https://github.com/DCSBL/ha-homewizard-energy/releases/latest)
-2. Extract this zip in `config/custom_components`. (The config folder where configuration.yaml can be found)
-3. ❗**Restart Home Assistant**.
-4. Please come back now and then to check if there is a new version available (this can be automated with HACS)
-
-### Usage
-1. Go to Configuration > Integrations.
-2. Home Assistant should tell you that a new device has been 'discovered'. (if not, please read 'manual configuration')
-3. Press configure to add this device, and give it a name if you want.
-4. :tada:
-
-#### Manual configuration
-If Home Assistant can't automaticly find your device, you can try to install your meter manually.
-1. Go to Configuration > Integrations > Add integration > search for 'HomeWizard Energy'.
-2. Enter the IP address from your device (eg. `192.168.1.107`).
-
-### Discussion
-Please join us at [the HASS forum](https://community.home-assistant.io/t/wi-fi-p1-dsmr-dongle-homewizard-energy) or the Dutch website [Tweakers (NL)](https://gathering.tweakers.net/forum/list_messages/2002754/last)
-
-### Frequent questions and issues
-1. **Home Assistant tells my device is offline after updating this integration**
-This is a known issue. Please restart your Home Assistant again. That should solve it for you.
-2. **I get a 'connection refused' error when trying to connect to `http:///api/v1/data`**
-Your P1 meter must be at firmware version `2.11` or higher. You can see this in the HomeWizard Energy app under 'Meters'. Your device should update within an hour after connecting it to the internet. If your device doesn't, contact HomeWizard Support.
-3. **Is the HomeWizard Wi-Fi kWh meter supported?**
-Yes, since 2021-06-03. You have to enable the API in the HomeWizard Energy app.
-4. **Can I see the daily/weekly/montly usage and history with this integration?**
-Yes, add the device to the [Home Energy Management](https://www.home-assistant.io/docs/energy/) dashboard
-
-### API documentation
-[HomeWizard Energy local API](https://homewizard-energy-api.readthedocs.io/#)
-
-### Disclaimer
-This integration is not developed, nor supported by HomeWizard.
+Replace `p1_meter__total_gas` to use the correct entity id. Now you can use `sensor. p1_meter_gas_timestamp`
\ No newline at end of file
diff --git a/custom_components/homewizard_energy/__init__.py b/custom_components/homewizard_energy/__init__.py
index ec52ed2..c02b86e 100644
--- a/custom_components/homewizard_energy/__init__.py
+++ b/custom_components/homewizard_energy/__init__.py
@@ -1,80 +1,28 @@
"""The Homewizard Energy integration."""
-import asyncio
import logging
-import aiohwenergy
-import async_timeout
-
-from homeassistant.config_entries import ConfigEntry
+from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.core import HomeAssistant
-from homeassistant.exceptions import ConfigEntryNotReady
-from homeassistant.helpers.aiohttp_client import async_get_clientsession
-from .const import CONF_API, COORDINATOR, DOMAIN, PLATFORMS
-from .coordinator import HWEnergyDeviceUpdateCoordinator as Coordinator
+from .const import DOMAIN, TARGET_DOMAIN
_LOGGER = logging.getLogger(__name__)
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Homewizard Energy from a config entry."""
+ hass.data.setdefault(DOMAIN, {})
_LOGGER.debug("__init__ async_setup_entry")
+ _LOGGER.warning("Sending config entry to core...")
- # Get api and do a initialization
- session = async_get_clientsession(hass)
- energy_api = aiohwenergy.HomeWizardEnergy(
- entry.data.get("host"), clientsession=session
- )
-
- # Validate connection
- initialized = False
- try:
- with async_timeout.timeout(10):
- await energy_api.initialize()
- initialized = True
-
- except (asyncio.TimeoutError, aiohwenergy.RequestError) as ex:
- _LOGGER.error(
- "Error connecting to the Energy device at %s",
- energy_api.host,
- )
- raise ConfigEntryNotReady from ex
-
- except aiohwenergy.DisabledError as ex:
- _LOGGER.error("API disabled, API must be enabled in the app")
- raise ConfigEntryNotReady from ex
-
- except aiohwenergy.AiohwenergyException as ex:
- _LOGGER.error("Unknown Energy API error occurred")
- raise ConfigEntryNotReady from ex
-
- except Exception as ex: # pylint: disable=broad-except
- _LOGGER.error(
- "Unknown error connecting with Energy Device at %s",
- energy_api.host,
- )
- raise ConfigEntryNotReady from ex
-
- finally:
- if not initialized:
- await energy_api.close()
-
- # Create coordinator
- coordinator = Coordinator(hass, energy_api)
- await coordinator.async_config_entry_first_refresh()
-
- # Finalize
- hass.data.setdefault(DOMAIN, {})
- hass.data[DOMAIN][entry.data["unique_id"]] = {
- COORDINATOR: coordinator,
- CONF_API: energy_api,
- }
-
- for component in PLATFORMS:
- hass.async_create_task(
- hass.config_entries.async_forward_entry_setup(entry, component)
+ hass.async_create_task(
+ hass.config_entries.flow.async_init(
+ TARGET_DOMAIN,
+ context={"source": SOURCE_IMPORT, "old_config_entry_id": entry.entry_id},
+ data=entry.data,
)
+ )
return True
@@ -83,19 +31,4 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
_LOGGER.debug("__init__ async_unload_entry")
- unload_ok = all(
- await asyncio.gather(
- *(
- hass.config_entries.async_forward_entry_unload(entry, component)
- for component in PLATFORMS
- )
- )
- )
-
- if unload_ok:
- config_data = hass.data[DOMAIN].pop(entry.data["unique_id"])
- if "api" in config_data:
- energy_api = config_data[CONF_API]
- await energy_api.close()
-
- return unload_ok
+ return True
diff --git a/custom_components/homewizard_energy/config_flow.py b/custom_components/homewizard_energy/config_flow.py
index b17b6ba..7de2686 100644
--- a/custom_components/homewizard_energy/config_flow.py
+++ b/custom_components/homewizard_energy/config_flow.py
@@ -4,22 +4,13 @@
import logging
from typing import Any
-import aiohwenergy
-from aiohwenergy.hwenergy import SUPPORTED_DEVICES
-import async_timeout
-from voluptuous import All, Length, Required, Schema
-from voluptuous.util import Lower
-
from homeassistant import config_entries
-from homeassistant.components import zeroconf
-from homeassistant.const import CONF_HOST, CONF_IP_ADDRESS, CONF_PORT
from homeassistant.data_entry_flow import FlowResult
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
-
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Handle a config flow for P1 meter."""
@@ -36,154 +27,4 @@ async def async_step_user(
_LOGGER.debug("config_flow async_step_user")
- if user_input is None:
- return self.async_show_form(
- step_id="user",
- data_schema=Schema(
- {
- Required(CONF_IP_ADDRESS): str,
- }
- ),
- errors=None,
- )
-
- entry_info = {
- CONF_IP_ADDRESS: user_input[CONF_IP_ADDRESS],
- CONF_PORT: 80,
- }
-
- return await self.async_step_check(entry_info)
-
- async def async_step_zeroconf(
- self, discovery_info: zeroconf.ZeroconfServiceInfo
- ) -> FlowResult:
- """Handle zeroconf discovery."""
-
- _LOGGER.debug("config_flow async_step_zeroconf")
-
- # Validate doscovery entry
- if (
- "api_enabled" not in discovery_info.properties
- or "path" not in discovery_info.properties
- or "product_name" not in discovery_info.properties
- or "product_type" not in discovery_info.properties
- or "serial" not in discovery_info.properties
- ):
- return self.async_abort(reason="invalid_discovery_parameters")
-
- if (discovery_info.properties["path"]) != "/api/v1":
- return self.async_abort(reason="unsupported_api_version")
-
- if (discovery_info.properties["api_enabled"]) != "1":
- return self.async_abort(reason="api_not_enabled")
-
- # Pass parameters
- entry_info = {
- CONF_IP_ADDRESS: discovery_info.host,
- CONF_PORT: discovery_info.port,
- }
-
- return await self.async_step_check(entry_info)
-
- async def async_step_check(self, entry_info):
- """Validate API connection and fetch metadata."""
-
- _LOGGER.debug("config_flow async_step_check")
-
- # Make connection with device
- energy_api = aiohwenergy.HomeWizardEnergy(entry_info[CONF_IP_ADDRESS])
-
- initialized = False
- try:
- with async_timeout.timeout(10):
- await energy_api.initialize()
- if energy_api.device is not None:
- initialized = True
-
- except aiohwenergy.DisabledError:
- _LOGGER.error("API disabled, API must be enabled in the app")
- return self.async_abort(reason="api_not_enabled")
-
- except Exception: # pylint: disable=broad-except
- _LOGGER.error(
- "Error connecting with Energy Device at %s",
- entry_info[CONF_IP_ADDRESS],
- )
- return self.async_abort(reason="unknown_error")
-
- finally:
- await energy_api.close()
-
- if not initialized:
- _LOGGER.error("Initialization failed")
- return self.async_abort(reason="unknown_error")
-
- # Validate metadata
- if energy_api.device.api_version != "v1":
- return self.async_abort(reason="unsupported_api_version")
-
- if energy_api.device.product_type not in SUPPORTED_DEVICES:
- _LOGGER.error(
- "Device (%s) not supported by integration",
- energy_api.device.product_type,
- )
- return self.async_abort(reason="device_not_supported")
-
- # Configure device
- entry_info["product_name"] = energy_api.device.product_name
- entry_info["product_type"] = energy_api.device.product_type
- entry_info["serial"] = energy_api.device.serial
-
- self.context[CONF_HOST] = entry_info[CONF_IP_ADDRESS]
- self.context[CONF_PORT] = entry_info[CONF_PORT]
- self.context["product_name"] = entry_info["product_name"]
- self.context["product_type"] = entry_info["product_type"]
- self.context["serial"] = entry_info["serial"]
- self.context[
- "unique_id"
- ] = f"{entry_info['product_type']}_{entry_info['serial']}"
- self.context[
- "name"
- ] = f"{self.context['product_name']} ({self.context['serial'][-6:]})"
-
- await self.async_set_unique_id(self.context["unique_id"])
- self._abort_if_unique_id_configured(updates=entry_info)
-
- self.context["title_placeholders"] = {
- "name": self.context["name"],
- "unique_id": self.context["unique_id"],
- }
-
- return await self.async_step_confirm()
-
- async def async_step_confirm(self, user_input=None):
- """Handle user-confirmation of node."""
-
- _LOGGER.debug("config_flow async_step_confirm")
-
- if user_input is None:
- return self.async_show_form(
- step_id="confirm",
- description_placeholders={"name": self.context["product_name"]},
- data_schema=Schema(
- {
- Required("name", default=self.context["product_name"]): All(
- str, Length(min=1)
- )
- }
- ),
- errors=None,
- )
-
- # Format name
- self.context["custom_name"] = user_input["name"]
- if Lower(self.context["product_name"]) != Lower(user_input["name"]):
- title = f"{self.context['product_name']} ({self.context['custom_name']})"
- else:
- title = self.context["custom_name"]
-
- # Finish up
- return self.async_create_entry(
- title=title,
- data=self.context,
- )
+ return self.async_abort(reason="manual_not_supported")
diff --git a/custom_components/homewizard_energy/const.py b/custom_components/homewizard_energy/const.py
index 35cb8ca..1a24926 100644
--- a/custom_components/homewizard_energy/const.py
+++ b/custom_components/homewizard_energy/const.py
@@ -2,44 +2,4 @@
# Set up.
DOMAIN = "homewizard_energy"
-COORDINATOR = "coordinator"
-MANUFACTURER_NAME = "HomeWizard"
-PLATFORMS = ["sensor", "switch"]
-
-# Platform config.
-CONF_SERIAL = "serial"
-CONF_API = "api"
-CONF_MODEL = "model"
-CONF_SW_VERSION = "sw_ver"
-CONF_DATA = "data"
-
-# Service attributes.
-ATTR_ACTIVE_POWER_L1_W = "active_power_l1_w"
-ATTR_ACTIVE_POWER_L2_W = "active_power_l2_w"
-ATTR_ACTIVE_POWER_L3_W = "active_power_l3_w"
-ATTR_ACTIVE_POWER_W = "active_power_w"
-ATTR_GAS_TIMESTAMP = "gas_timestamp"
-ATTR_METER_MODEL = "meter_model"
-ATTR_SMR_VERSION = "smr_version"
-ATTR_TOTAL_ENERGY_EXPORT_T1_KWH = "total_power_export_t1_kwh"
-ATTR_TOTAL_ENERGY_EXPORT_T2_KWH = "total_power_export_t2_kwh"
-ATTR_TOTAL_ENERGY_IMPORT_T1_KWH = "total_power_import_t1_kwh"
-ATTR_TOTAL_ENERGY_IMPORT_T2_KWH = "total_power_import_t2_kwh"
-ATTR_TOTAL_GAS_M3 = "total_gas_m3"
-ATTR_WIFI_SSID = "wifi_ssid"
-ATTR_WIFI_STRENGTH = "wifi_strength"
-
-# State attributes
-ATTR_POWER_ON = "power_on"
-ATTR_SWITCHLOCK = "switch_lock"
-ATTR_BRIGHTNESS = "brightness"
-
-# Default values.
-DEFAULT_STR_VALUE = "undefined"
-DEVICE_DEFAULT_NAME = "P1 Meter"
-
-# Device models
-MODEL_P1 = "HWE-P1"
-MODEL_KWH_1 = "SDM230-wifi"
-MODEL_KWH_3 = "SDM630-wifi"
-MODEL_SOCKET = "HWE-SKT"
+TARGET_DOMAIN = "homewizard"
diff --git a/custom_components/homewizard_energy/coordinator.py b/custom_components/homewizard_energy/coordinator.py
deleted file mode 100644
index 0e5fa2b..0000000
--- a/custom_components/homewizard_energy/coordinator.py
+++ /dev/null
@@ -1,93 +0,0 @@
-"""Update coordinator for HomeWizard Energy."""
-
-from datetime import timedelta
-import logging
-
-import aiohwenergy
-import async_timeout
-
-from homeassistant.const import CONF_API_VERSION, CONF_ID, CONF_NAME, CONF_STATE
-from homeassistant.core import HomeAssistant
-from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
-
-from .const import (
- ATTR_BRIGHTNESS,
- ATTR_POWER_ON,
- ATTR_SWITCHLOCK,
- CONF_DATA,
- CONF_MODEL,
- CONF_SW_VERSION,
- MODEL_P1,
-)
-
-_LOGGER = logging.getLogger(__name__)
-
-
-class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator):
- """Gather data for the energy device."""
-
- def __init__(
- self,
- hass: HomeAssistant,
- api: aiohwenergy.HomeWizardEnergy,
- ) -> None:
- """Initialize Update Coordinator."""
-
- self.api = api
-
- update_interval = self.get_update_interval()
- super().__init__(hass, _LOGGER, name="", update_interval=update_interval)
-
- def get_update_interval(self) -> timedelta:
- """Return best interval for product type."""
- try:
- product_type = self.api.device.product_type
- except AttributeError:
- product_type = "Unknown"
-
- if product_type == MODEL_P1:
- try:
- smr_version = self.api.data.smr_version
- if smr_version == 50:
- return timedelta(seconds=1)
-
- except AttributeError:
- pass
-
- return timedelta(seconds=5)
-
- async def _async_update_data(self) -> dict:
- """Fetch all device and sensor data from api."""
- try:
- async with async_timeout.timeout(10):
- # Update all properties
- status = await self.api.update()
-
- if not status:
- raise Exception("Failed to fetch data")
-
- data = {
- CONF_NAME: self.api.device.product_name,
- CONF_MODEL: self.api.device.product_type,
- CONF_ID: self.api.device.serial,
- CONF_SW_VERSION: self.api.device.firmware_version,
- CONF_API_VERSION: self.api.device.api_version,
- CONF_DATA: {},
- CONF_STATE: None,
- }
-
- for datapoint in self.api.data.available_datapoints:
- data[CONF_DATA][datapoint] = getattr(self.api.data, datapoint)
-
- if self.api.state is not None:
- data[CONF_STATE] = {
- ATTR_POWER_ON: self.api.state.power_on,
- ATTR_SWITCHLOCK: self.api.state.switch_lock,
- ATTR_BRIGHTNESS: self.api.state.brightness,
- }
-
- except Exception as ex:
- raise UpdateFailed(ex) from ex
-
- self.name = data[CONF_NAME]
- return data
diff --git a/custom_components/homewizard_energy/errors.py b/custom_components/homewizard_energy/errors.py
deleted file mode 100644
index c32fda7..0000000
--- a/custom_components/homewizard_energy/errors.py
+++ /dev/null
@@ -1,14 +0,0 @@
-"""Errors for the HomeWizard Energy component."""
-from homeassistant.exceptions import HomeAssistantError
-
-
-class HwEnergyException(HomeAssistantError):
- """Base class for HomeWizard Energy exceptions."""
-
-
-class CannotConnect(HwEnergyException):
- """Unable to connect to the energy Device."""
-
-
-class AuthenticationRequired(HwEnergyException):
- """Unknown error occurred."""
diff --git a/custom_components/homewizard_energy/manifest.json b/custom_components/homewizard_energy/manifest.json
index ee5cfbb..b6375a8 100644
--- a/custom_components/homewizard_energy/manifest.json
+++ b/custom_components/homewizard_energy/manifest.json
@@ -1,12 +1,11 @@
{
"codeowners": ["@DCSBL"],
- "config_flow": true,
+ "config_flow": false,
"documentation": "https://github.com/DCSBL/ha-homewizard-energy",
"domain": "homewizard_energy",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/DCSBL/ha-homewizard-energy/issues",
"name": "HomeWizard Energy",
"requirements": ["aiohwenergy==0.8.0"],
- "version": "0.0.0",
- "zeroconf": ["_hwenergy._tcp.local."]
+ "version": "0.0.0"
}
diff --git a/custom_components/homewizard_energy/sensor.py b/custom_components/homewizard_energy/sensor.py
deleted file mode 100644
index 22d388c..0000000
--- a/custom_components/homewizard_energy/sensor.py
+++ /dev/null
@@ -1,229 +0,0 @@
-"""Creates Homewizard Energy sensor entities."""
-from __future__ import annotations
-
-import logging
-from typing import Final
-
-from homeassistant.components.sensor import (
- STATE_CLASS_MEASUREMENT,
- STATE_CLASS_TOTAL_INCREASING,
- SensorEntity,
- SensorEntityDescription,
-)
-from homeassistant.const import (
- CONF_ID,
- DEVICE_CLASS_ENERGY,
- DEVICE_CLASS_GAS,
- DEVICE_CLASS_POWER,
- DEVICE_CLASS_TIMESTAMP,
- ENERGY_KILO_WATT_HOUR,
- ENTITY_CATEGORY_DIAGNOSTIC,
- PERCENTAGE,
- POWER_WATT,
- VOLUME_CUBIC_METERS,
-)
-from homeassistant.helpers.entity import DeviceInfo
-from homeassistant.helpers.update_coordinator import CoordinatorEntity
-
-from .const import (
- ATTR_ACTIVE_POWER_L1_W,
- ATTR_ACTIVE_POWER_L2_W,
- ATTR_ACTIVE_POWER_L3_W,
- ATTR_ACTIVE_POWER_W,
- ATTR_GAS_TIMESTAMP,
- ATTR_METER_MODEL,
- ATTR_SMR_VERSION,
- ATTR_TOTAL_ENERGY_EXPORT_T1_KWH,
- ATTR_TOTAL_ENERGY_EXPORT_T2_KWH,
- ATTR_TOTAL_ENERGY_IMPORT_T1_KWH,
- ATTR_TOTAL_ENERGY_IMPORT_T2_KWH,
- ATTR_TOTAL_GAS_M3,
- ATTR_WIFI_SSID,
- ATTR_WIFI_STRENGTH,
- CONF_API,
- CONF_DATA,
- CONF_MODEL,
- CONF_SW_VERSION,
- COORDINATOR,
- DOMAIN,
-)
-
-_LOGGER = logging.getLogger(__name__)
-
-SENSORS: Final[tuple[SensorEntityDescription, ...]] = (
- SensorEntityDescription(
- key=ATTR_SMR_VERSION,
- name="SMR Version",
- icon="mdi:counter",
- entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
- ),
- SensorEntityDescription(
- key=ATTR_METER_MODEL,
- name="Model",
- icon="mdi:gauge",
- entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
- ),
- SensorEntityDescription(
- key=ATTR_WIFI_SSID,
- name="Wifi SSID",
- icon="mdi:wifi",
- entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
- ),
- SensorEntityDescription(
- key=ATTR_WIFI_STRENGTH,
- name="Wifi Strength",
- icon="mdi:wifi",
- native_unit_of_measurement=PERCENTAGE,
- state_class=STATE_CLASS_MEASUREMENT,
- entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
- ),
- SensorEntityDescription(
- key=ATTR_TOTAL_ENERGY_IMPORT_T1_KWH,
- name="Total Power Import T1",
- native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
- device_class=DEVICE_CLASS_ENERGY,
- state_class=STATE_CLASS_TOTAL_INCREASING,
- ),
- SensorEntityDescription(
- key=ATTR_TOTAL_ENERGY_IMPORT_T2_KWH,
- name="Total Power Import T2",
- native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
- device_class=DEVICE_CLASS_ENERGY,
- state_class=STATE_CLASS_TOTAL_INCREASING,
- ),
- SensorEntityDescription(
- key=ATTR_TOTAL_ENERGY_EXPORT_T1_KWH,
- name="Total Power Export T1",
- native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
- device_class=DEVICE_CLASS_ENERGY,
- state_class=STATE_CLASS_TOTAL_INCREASING,
- ),
- SensorEntityDescription(
- key=ATTR_TOTAL_ENERGY_EXPORT_T2_KWH,
- name="Total Power Export T2",
- native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
- device_class=DEVICE_CLASS_ENERGY,
- state_class=STATE_CLASS_TOTAL_INCREASING,
- ),
- SensorEntityDescription(
- key=ATTR_ACTIVE_POWER_W,
- name="Active Power",
- native_unit_of_measurement=POWER_WATT,
- device_class=DEVICE_CLASS_POWER,
- state_class=STATE_CLASS_MEASUREMENT,
- ),
- SensorEntityDescription(
- key=ATTR_ACTIVE_POWER_L1_W,
- name="Active Power L1",
- native_unit_of_measurement=POWER_WATT,
- device_class=DEVICE_CLASS_POWER,
- state_class=STATE_CLASS_MEASUREMENT,
- ),
- SensorEntityDescription(
- key=ATTR_ACTIVE_POWER_L2_W,
- name="Active Power L2",
- native_unit_of_measurement=POWER_WATT,
- device_class=DEVICE_CLASS_POWER,
- state_class=STATE_CLASS_MEASUREMENT,
- ),
- SensorEntityDescription(
- key=ATTR_ACTIVE_POWER_L3_W,
- name="Active Power L3",
- native_unit_of_measurement=POWER_WATT,
- device_class=DEVICE_CLASS_POWER,
- state_class=STATE_CLASS_MEASUREMENT,
- ),
- SensorEntityDescription(
- key=ATTR_TOTAL_GAS_M3,
- name="Total Gas",
- native_unit_of_measurement=VOLUME_CUBIC_METERS,
- device_class=DEVICE_CLASS_GAS,
- state_class=STATE_CLASS_TOTAL_INCREASING,
- ),
- SensorEntityDescription(
- key=ATTR_GAS_TIMESTAMP,
- name="Gas Timestamp",
- device_class=DEVICE_CLASS_TIMESTAMP,
- ),
-)
-
-
-async def async_setup_entry(hass, entry, async_add_entities):
- """Config entry example."""
- energy_api = hass.data[DOMAIN][entry.data["unique_id"]][CONF_API]
- coordinator = hass.data[DOMAIN][entry.data["unique_id"]][COORDINATOR]
-
- if energy_api.data is not None:
- entities = []
- for description in SENSORS:
- if description.key in energy_api.data.available_datapoints:
- entities.append(HWEnergySensor(coordinator, entry.data, description))
- async_add_entities(entities, update_before_add=True)
-
- return True
-
- return False
-
-
-class HWEnergySensor(CoordinatorEntity, SensorEntity):
- """Representation of a HomeWizard Energy Sensor."""
-
- unique_id = None
- name = None
-
- def __init__(self, coordinator, entry_data, description):
- """Initialize Sensor Domain."""
-
- super().__init__(coordinator)
- self.entity_description = description
- self.coordinator = coordinator
- self.entry_data = entry_data
-
- # Config attributes.
- self.name = "{} {}".format(entry_data["custom_name"], description.name)
- self.data_type = description.key
- self.unique_id = "{}_{}".format(entry_data["unique_id"], description.key)
-
- # Some values are given, but set to NULL (eg. gas_timestamp when no gas meter is connected)
- if self.data[CONF_DATA][self.data_type] is None:
- self.entity_description.entity_registry_enabled_default = False
-
- # Special case for export, not everyone has solarpanels
- # The change that 'export' is non-zero when you have solar panels is nil
- if self.data_type in [
- ATTR_TOTAL_ENERGY_EXPORT_T1_KWH,
- ATTR_TOTAL_ENERGY_EXPORT_T2_KWH,
- ]:
- if self.data[CONF_DATA][self.data_type] == 0:
- self.entity_description.entity_registry_enabled_default = False
-
- @property
- def device_info(self) -> DeviceInfo:
- """Return device information."""
- return {
- "name": self.entry_data["custom_name"],
- "manufacturer": "HomeWizard",
- "sw_version": self.data[CONF_SW_VERSION],
- "model": self.data[CONF_MODEL],
- "identifiers": {(DOMAIN, self.data[CONF_ID])},
- }
-
- @property
- def data(self):
- """Return data object from DataUpdateCoordinator."""
- return self.coordinator.data
-
- @property
- def icon(self):
- """Return the icon."""
- return self.entity_description.icon
-
- @property
- def state(self):
- """Return state of meter."""
- return self.data[CONF_DATA][self.data_type]
-
- @property
- def available(self):
- """Return availability of meter."""
- return self.data_type in self.data[CONF_DATA]
diff --git a/custom_components/homewizard_energy/strings.json b/custom_components/homewizard_energy/strings.json
index e264382..10e76b0 100644
--- a/custom_components/homewizard_energy/strings.json
+++ b/custom_components/homewizard_energy/strings.json
@@ -7,8 +7,7 @@
}
},
"abort": {
- "single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]",
- "no_devices_found": "[%key:common::config_flow::abort::no_devices_found%]"
+ "manual_not_supported": "This integration has been moved to core. Please remove 'homewizard_energt' from 'custom_integrations'"
}
}
-}
\ No newline at end of file
+}
diff --git a/custom_components/homewizard_energy/switch.py b/custom_components/homewizard_energy/switch.py
deleted file mode 100644
index d7a47de..0000000
--- a/custom_components/homewizard_energy/switch.py
+++ /dev/null
@@ -1,128 +0,0 @@
-"""Creates Homewizard Energy switch entities."""
-from __future__ import annotations
-
-from typing import Any, Final
-
-import logging
-from homeassistant.components.switch import (
- DEVICE_CLASS_OUTLET,
- DEVICE_CLASS_SWITCH,
- SwitchEntity,
- SwitchEntityDescription,
-)
-from homeassistant.config_entries import ConfigEntry
-from homeassistant.const import CONF_ID, CONF_STATE, ENTITY_CATEGORY_CONFIG
-from homeassistant.core import HomeAssistant
-from homeassistant.helpers.entity import DeviceInfo
-from homeassistant.helpers.entity_platform import AddEntitiesCallback
-from homeassistant.helpers.update_coordinator import (
- CoordinatorEntity,
-)
-
-from .const import (
- ATTR_POWER_ON,
- ATTR_SWITCHLOCK,
- CONF_API,
- CONF_MODEL,
- CONF_SW_VERSION,
- COORDINATOR,
- DOMAIN,
-)
-
-Logger = logging.getLogger(__name__)
-
-SWITCHES: Final[tuple[SwitchEntityDescription, ...]] = (
- SwitchEntityDescription(
- key=ATTR_POWER_ON, name="Switch", device_class=DEVICE_CLASS_OUTLET
- ),
- SwitchEntityDescription(
- key=ATTR_SWITCHLOCK,
- name="Switch Lock",
- device_class=DEVICE_CLASS_SWITCH,
- icon="mdi:lock",
- entity_category=ENTITY_CATEGORY_CONFIG,
- ),
-)
-
-
-async def async_setup_entry(
- hass: HomeAssistant,
- entry: ConfigEntry,
- async_add_entities: AddEntitiesCallback,
-) -> None:
- """Set up switches."""
-
- energy_api = hass.data[DOMAIN][entry.data["unique_id"]][CONF_API]
- coordinator = hass.data[DOMAIN][entry.data["unique_id"]][COORDINATOR]
-
- if energy_api.state is not None:
- entities = []
- for description in SWITCHES:
- entities.append(
- HWEnergySwitch(coordinator, entry.data, description, energy_api)
- )
-
- async_add_entities(entities)
-
-
-class HWEnergySwitch(CoordinatorEntity, SwitchEntity):
- """Representation of a HomeWizard Energy Switch."""
-
- unique_id = None
- name = None
-
- def __init__(self, coordinator, entry_data, description, api) -> None:
- """Initialize the switch."""
- super().__init__(coordinator)
- self.entity_description = description
- self.coordinator = coordinator
- self.entry_data = entry_data
- self.api = api
-
- # Config attributes
- self.name = "%s %s" % (entry_data["custom_name"], description.name)
- self.unique_id = "%s_%s" % (entry_data["unique_id"], description.key)
- self.data_type = description.key
-
- @property
- def data(self) -> dict[str, Any]:
- """Return data from DataUpdateCoordinator."""
- return self.coordinator.data
-
- @property
- def device_info(self) -> DeviceInfo:
- """Return information about the device."""
- return {
- "name": self.entry_data["custom_name"],
- "manufacturer": "HomeWizard",
- "sw_version": self.data[CONF_SW_VERSION],
- "model": self.data[CONF_MODEL],
- "identifiers": {(DOMAIN, self.data[CONF_ID])},
- }
-
- @property
- def is_on(self):
- """Return true if switch is on."""
- return self.data[CONF_STATE][self.data_type]
-
- async def async_turn_on(self, **kwargs: Any) -> None:
- """Turn the switch on."""
- if self.data_type == ATTR_POWER_ON:
- await self.api.state.set(power_on=True)
- elif self.data_type == ATTR_SWITCHLOCK:
- await self.api.state.set(switch_lock=True)
- else:
- Logger.error("Internal error, unknown action")
-
- await self.coordinator.async_refresh()
-
- async def async_turn_off(self, **kwargs: Any) -> None:
- """Turn the switch off."""
- if self.data_type == ATTR_POWER_ON:
- await self.api.state.set(power_on=False)
- elif self.data_type == ATTR_SWITCHLOCK:
- await self.api.state.set(switch_lock=False)
- else:
- Logger.error("Internal error, unknown action")
-
- await self.coordinator.async_refresh()
diff --git a/custom_components/homewizard_energy/translations/en.json b/custom_components/homewizard_energy/translations/en.json
index 1cd1990..10e76b0 100644
--- a/custom_components/homewizard_energy/translations/en.json
+++ b/custom_components/homewizard_energy/translations/en.json
@@ -1,28 +1,13 @@
{
- "title": "Homewizard Energy",
- "config": {
- "flow_title": "{name}",
- "abort": {
- "no_devices_found": "No devices found on the network",
- "single_instance_allowed": "Already configured. Only a single configuration possible.",
- "api_not_enabled": "Device API not activated.",
- "manual_config_request_error": "Could not connect to device. Please check the IP address and that your device is reachable from Home Assistant",
- "manual_config_unknown_error": "Could not connect to device. Please check if you entered the correct IP address and check if the API is enabled.",
- "manual_config_unsupported_api_version": "API version not supported",
- "invalid_discovery_parameters": "Error: invalid_discovery_parameters"
- },
- "step": {
- "user":
- {
- "data": {
- "ip_address": "IP Address"
- },
- "description": "Enter the IP address of your HomeWizard Energy device to integrate with Home Assistant.",
- "title": "Configure device"
- },
- "discovery_confirm": {
- "description": "Please enter a name for your {name}:"
- }
- }
+ "title": "Homewizard Energy",
+ "config": {
+ "step": {
+ "confirm": {
+ "description": "[%key:common::config_flow::description::confirm_setup%]"
+ }
+ },
+ "abort": {
+ "manual_not_supported": "This integration has been moved to core. Please remove 'homewizard_energt' from 'custom_integrations'"
}
+ }
}
diff --git a/custom_components/homewizard_energy/translations/nl.json b/custom_components/homewizard_energy/translations/nl.json
index e10581f..6e9249f 100644
--- a/custom_components/homewizard_energy/translations/nl.json
+++ b/custom_components/homewizard_energy/translations/nl.json
@@ -1,29 +1,13 @@
{
- "title": "Homewizard Energy",
- "config": {
- "flow_title": "{name}",
- "abort": {
- "no_devices_found": "Geen apparaten gevonden binnen het netwerk",
- "single_instance_allowed": "Apparaat is al toegevoegd aan Home Assistant",
- "api_not_enabled": "API van apparaat niet actief",
- "manual_config_request_error": "Kan geen verbinding maken met apparaat. Controleer of het juiste IP adres is ingevuld en dat het apparaat bereikbaar is vanuit Home Assistant",
- "manual_config_unknown_error": "Kan geen verbinding maken met apparaat. Controleer of het juiste IP adres is ingevuld en dat het apparaat bereikbaar is vanuit Home Assistant",
- "manual_config_unsupported_api_version": "API versie niet ondersteund",
- "invalid_discovery_parameters": "Fout: invalid_discovery_parameters"
- },
-
- "step": {
- "user":
- {
- "data": {
- "ip_address": "IP Address"
- },
- "description": "Vul het IP adres in van je HomeWizard Energy apparaat",
- "title": "Apparaat toevoegen"
- },
- "discovery_confirm": {
- "description": "Geef een naam aan je apparaat:"
- }
- }
+ "title": "Homewizard Energy",
+ "config": {
+ "step": {
+ "confirm": {
+ "description": "[%key:common::config_flow::description::confirm_setup%]"
+ }
+ },
+ "abort": {
+ "manual_not_supported": "Deze integratie is verplaatst naar core. Verwijder homewizard_energy uit 'custom_integrations'"
}
+ }
}
diff --git a/hacs.json b/hacs.json
index 469a806..aff084d 100644
--- a/hacs.json
+++ b/hacs.json
@@ -2,7 +2,7 @@
"name": "HomeWizard Energy",
"render_readme": true,
"domains": ["sensor", "switch"],
- "homeassistant": "2021.11.0",
+ "homeassistant": "2022.2.2",
"iot_class": "local_polling",
"zip_release": true,
"filename": "homewizard_energy.zip"