-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/ctek pypi #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,12 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| from ctek import NanogridAir | ||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.config_entries import ConfigFlow, ConfigFlowResult | ||
| from homeassistant.const import CONF_URL | ||
|
|
||
| from .api import fetch_mac, get_ip | ||
| from .const import DOMAIN | ||
|
|
||
| API_DEFAULT = "http://ctek-ng-air.local/meter/" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not here, but below. Conflig flow do not have a reason to use the API url any more?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||
|
|
@@ -37,8 +37,9 @@ async def async_step_user(self, user_input=None) -> ConfigFlowResult: | |
| # Attempt to automatically detect the device | ||
| if user_input is None: | ||
| try: | ||
| if await get_ip(): | ||
| mac_address = await fetch_mac() | ||
| if await NanogridAir().get_ip(): | ||
| status = await NanogridAir().fetch_status() | ||
| mac_address = status.device_info.mac | ||
| if mac_address: | ||
| unique_id = mac_address | ||
| await self.async_set_unique_id(unique_id) | ||
|
|
@@ -61,8 +62,9 @@ async def async_step_user(self, user_input=None) -> ConfigFlowResult: | |
|
|
||
| # Handle user input | ||
| try: | ||
| if await get_ip(user_input[CONF_URL]): | ||
| mac_address = await fetch_mac() | ||
| if await NanogridAir(device_ip=user_input[CONF_URL]).get_ip(): | ||
| status = await NanogridAir().fetch_status() | ||
| mac_address = status.device_info.mac | ||
| if mac_address: | ||
| unique_id = mac_address | ||
| await self.async_set_unique_id(unique_id) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
|
|
||
| from datetime import timedelta | ||
|
|
||
| from ctek import NanogridAir | ||
|
|
||
| from homeassistant.components.sensor import ( | ||
| SensorDeviceClass, | ||
| SensorEntity, | ||
|
|
@@ -24,8 +26,6 @@ | |
| DataUpdateCoordinator, | ||
| ) | ||
|
|
||
| from .api import fetch_meter_data | ||
|
|
||
| SENSOR = { | ||
| "current_0": SensorEntityDescription( | ||
| key="current_0", | ||
|
|
@@ -106,7 +106,7 @@ async def async_setup_entry( | |
| """Set up sensor entities for the integration entry.""" | ||
|
|
||
| async def update_data(): | ||
| return await fetch_meter_data() | ||
| return await NanogridAir().fetch_meter_data() | ||
|
|
||
| coordinator = DataUpdateCoordinator( | ||
| hass, | ||
|
|
@@ -149,23 +149,23 @@ def __init__( | |
| def native_value(self) -> str | None: | ||
| """Return the state of the sensor.""" | ||
| data = self.coordinator.data | ||
| if data is None: | ||
| if data is None or isinstance(data, dict): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why filter out dicts? |
||
| return None | ||
|
|
||
| if self._sensor_id.startswith("current_"): | ||
| index = int(self._sensor_id.split("_")[-1]) | ||
| return data.get("current", [None, None, None])[index] | ||
| return getattr(data, "current", [None])[index] | ||
| if self._sensor_id.startswith("voltage_"): | ||
| index = int(self._sensor_id.split("_")[-1]) | ||
| return data.get("voltage", [None, None, None])[index] | ||
| return getattr(data, "voltage", [None])[index] | ||
| if self._sensor_id == "power_in": | ||
| return data.get("activePowerIn", None) | ||
| return getattr(data, "active_power_in", None) | ||
| if self._sensor_id == "power_out": | ||
| return data.get("activePowerOut", None) | ||
| return getattr(data, "active_power_out", None) | ||
| if self._sensor_id == "total_energy_import": | ||
| return data.get("totalEnergyActiveImport", None) | ||
| return getattr(data, "total_energy_active_import", None) | ||
| if self._sensor_id == "total_energy_export": | ||
| return data.get("totalEnergyActiveExport", None) | ||
| return getattr(data, "total_energy_active_export", None) | ||
| return None | ||
|
|
||
| @property | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed