Bump pydiscovergy to 2.0.1 (#97186)
parent
fb00cd8963
commit
a0b61a1188
|
@ -14,7 +14,7 @@ from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
|
|
||||||
from .const import APP_NAME, DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import DiscovergyUpdateCoordinator
|
from .coordinator import DiscovergyUpdateCoordinator
|
||||||
|
|
||||||
PLATFORMS = [Platform.SENSOR]
|
PLATFORMS = [Platform.SENSOR]
|
||||||
|
@ -38,7 +38,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
api_client=pydiscovergy.Discovergy(
|
api_client=pydiscovergy.Discovergy(
|
||||||
email=entry.data[CONF_EMAIL],
|
email=entry.data[CONF_EMAIL],
|
||||||
password=entry.data[CONF_PASSWORD],
|
password=entry.data[CONF_PASSWORD],
|
||||||
app_name=APP_NAME,
|
|
||||||
httpx_client=get_async_client(hass),
|
httpx_client=get_async_client(hass),
|
||||||
authentication=BasicAuth(),
|
authentication=BasicAuth(),
|
||||||
),
|
),
|
||||||
|
@ -49,7 +48,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
try:
|
try:
|
||||||
# try to get meters from api to check if credentials are still valid and for later use
|
# try to get meters from api to check if credentials are still valid and for later use
|
||||||
# if no exception is raised everything is fine to go
|
# if no exception is raised everything is fine to go
|
||||||
discovergy_data.meters = await discovergy_data.api_client.get_meters()
|
discovergy_data.meters = await discovergy_data.api_client.meters()
|
||||||
except discovergyError.InvalidLogin as err:
|
except discovergyError.InvalidLogin as err:
|
||||||
raise ConfigEntryAuthFailed("Invalid email or password") from err
|
raise ConfigEntryAuthFailed("Invalid email or password") from err
|
||||||
except Exception as err: # pylint: disable=broad-except
|
except Exception as err: # pylint: disable=broad-except
|
||||||
|
@ -69,7 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
)
|
)
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
|
||||||
discovergy_data.coordinators[meter.get_meter_id()] = coordinator
|
discovergy_data.coordinators[meter.meter_id] = coordinator
|
||||||
|
|
||||||
hass.data[DOMAIN][entry.entry_id] = discovergy_data
|
hass.data[DOMAIN][entry.entry_id] = discovergy_data
|
||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
|
@ -16,7 +16,7 @@ from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||||
from homeassistant.data_entry_flow import FlowResult
|
from homeassistant.data_entry_flow import FlowResult
|
||||||
from homeassistant.helpers.httpx_client import get_async_client
|
from homeassistant.helpers.httpx_client import get_async_client
|
||||||
|
|
||||||
from .const import APP_NAME, DOMAIN
|
from .const import DOMAIN
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -82,10 +82,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
await pydiscovergy.Discovergy(
|
await pydiscovergy.Discovergy(
|
||||||
email=user_input[CONF_EMAIL],
|
email=user_input[CONF_EMAIL],
|
||||||
password=user_input[CONF_PASSWORD],
|
password=user_input[CONF_PASSWORD],
|
||||||
app_name=APP_NAME,
|
|
||||||
httpx_client=get_async_client(self.hass),
|
httpx_client=get_async_client(self.hass),
|
||||||
authentication=BasicAuth(),
|
authentication=BasicAuth(),
|
||||||
).get_meters()
|
).meters()
|
||||||
except discovergyError.HTTPError:
|
except discovergyError.HTTPError:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except discovergyError.InvalidLogin:
|
except discovergyError.InvalidLogin:
|
||||||
|
|
|
@ -3,4 +3,3 @@ from __future__ import annotations
|
||||||
|
|
||||||
DOMAIN = "discovergy"
|
DOMAIN = "discovergy"
|
||||||
MANUFACTURER = "Discovergy"
|
MANUFACTURER = "Discovergy"
|
||||||
APP_NAME = "homeassistant"
|
|
||||||
|
|
|
@ -47,9 +47,7 @@ class DiscovergyUpdateCoordinator(DataUpdateCoordinator[Reading]):
|
||||||
async def _async_update_data(self) -> Reading:
|
async def _async_update_data(self) -> Reading:
|
||||||
"""Get last reading for meter."""
|
"""Get last reading for meter."""
|
||||||
try:
|
try:
|
||||||
return await self.discovergy_client.get_last_reading(
|
return await self.discovergy_client.meter_last_reading(self.meter.meter_id)
|
||||||
self.meter.get_meter_id()
|
|
||||||
)
|
|
||||||
except AccessTokenExpired as err:
|
except AccessTokenExpired as err:
|
||||||
raise ConfigEntryAuthFailed(
|
raise ConfigEntryAuthFailed(
|
||||||
f"Auth expired while fetching last reading for meter {self.meter.get_meter_id()}"
|
f"Auth expired while fetching last reading for meter {self.meter.get_meter_id()}"
|
||||||
|
|
|
@ -19,9 +19,9 @@ TO_REDACT_METER = {
|
||||||
"serial_number",
|
"serial_number",
|
||||||
"full_serial_number",
|
"full_serial_number",
|
||||||
"location",
|
"location",
|
||||||
"fullSerialNumber",
|
"full_serial_number",
|
||||||
"printedFullSerialNumber",
|
"printed_full_serial_number",
|
||||||
"administrationNumber",
|
"administration_number",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ async def async_get_config_entry_diagnostics(
|
||||||
flattened_meter.append(async_redact_data(meter.__dict__, TO_REDACT_METER))
|
flattened_meter.append(async_redact_data(meter.__dict__, TO_REDACT_METER))
|
||||||
|
|
||||||
# get last reading for meter and make a dict of it
|
# get last reading for meter and make a dict of it
|
||||||
coordinator = data.coordinators[meter.get_meter_id()]
|
coordinator = data.coordinators[meter.meter_id]
|
||||||
last_readings[meter.get_meter_id()] = coordinator.data.__dict__
|
last_readings[meter.meter_id] = coordinator.data.__dict__
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"entry": async_redact_data(entry.as_dict(), TO_REDACT_CONFIG_ENTRY),
|
"entry": async_redact_data(entry.as_dict(), TO_REDACT_CONFIG_ENTRY),
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
"documentation": "https://www.home-assistant.io/integrations/discovergy",
|
"documentation": "https://www.home-assistant.io/integrations/discovergy",
|
||||||
"integration_type": "hub",
|
"integration_type": "hub",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"requirements": ["pydiscovergy==1.2.1"]
|
"requirements": ["pydiscovergy==2.0.1"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,8 +154,6 @@ async def async_setup_entry(
|
||||||
|
|
||||||
entities: list[DiscovergySensor] = []
|
entities: list[DiscovergySensor] = []
|
||||||
for meter in meters:
|
for meter in meters:
|
||||||
meter_id = meter.get_meter_id()
|
|
||||||
|
|
||||||
sensors = None
|
sensors = None
|
||||||
if meter.measurement_type == "ELECTRICITY":
|
if meter.measurement_type == "ELECTRICITY":
|
||||||
sensors = ELECTRICITY_SENSORS
|
sensors = ELECTRICITY_SENSORS
|
||||||
|
@ -167,7 +165,7 @@ async def async_setup_entry(
|
||||||
# check if this meter has this data, then add this sensor
|
# check if this meter has this data, then add this sensor
|
||||||
for key in {description.key, *description.alternative_keys}:
|
for key in {description.key, *description.alternative_keys}:
|
||||||
coordinator: DiscovergyUpdateCoordinator = data.coordinators[
|
coordinator: DiscovergyUpdateCoordinator = data.coordinators[
|
||||||
meter_id
|
meter.meter_id
|
||||||
]
|
]
|
||||||
if key in coordinator.data.values:
|
if key in coordinator.data.values:
|
||||||
entities.append(
|
entities.append(
|
||||||
|
@ -199,7 +197,7 @@ class DiscovergySensor(CoordinatorEntity[DiscovergyUpdateCoordinator], SensorEnt
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_unique_id = f"{meter.full_serial_number}-{data_key}"
|
self._attr_unique_id = f"{meter.full_serial_number}-{data_key}"
|
||||||
self._attr_device_info = DeviceInfo(
|
self._attr_device_info = DeviceInfo(
|
||||||
identifiers={(DOMAIN, meter.get_meter_id())},
|
identifiers={(DOMAIN, meter.meter_id)},
|
||||||
name=f"{meter.measurement_type.capitalize()} {meter.location.street} {meter.location.street_number}",
|
name=f"{meter.measurement_type.capitalize()} {meter.location.street} {meter.location.street_number}",
|
||||||
model=f"{meter.type} {meter.full_serial_number}",
|
model=f"{meter.type} {meter.full_serial_number}",
|
||||||
manufacturer=MANUFACTURER,
|
manufacturer=MANUFACTURER,
|
||||||
|
|
|
@ -1635,7 +1635,7 @@ pydelijn==1.1.0
|
||||||
pydexcom==0.2.3
|
pydexcom==0.2.3
|
||||||
|
|
||||||
# homeassistant.components.discovergy
|
# homeassistant.components.discovergy
|
||||||
pydiscovergy==1.2.1
|
pydiscovergy==2.0.1
|
||||||
|
|
||||||
# homeassistant.components.doods
|
# homeassistant.components.doods
|
||||||
pydoods==1.0.2
|
pydoods==1.0.2
|
||||||
|
|
|
@ -1214,7 +1214,7 @@ pydeconz==113
|
||||||
pydexcom==0.2.3
|
pydexcom==0.2.3
|
||||||
|
|
||||||
# homeassistant.components.discovergy
|
# homeassistant.components.discovergy
|
||||||
pydiscovergy==1.2.1
|
pydiscovergy==2.0.1
|
||||||
|
|
||||||
# homeassistant.components.android_ip_webcam
|
# homeassistant.components.android_ip_webcam
|
||||||
pydroid-ipcam==2.0.0
|
pydroid-ipcam==2.0.0
|
||||||
|
|
|
@ -14,7 +14,7 @@ from tests.components.discovergy.const import GET_METERS
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_meters() -> Mock:
|
def mock_meters() -> Mock:
|
||||||
"""Patch libraries."""
|
"""Patch libraries."""
|
||||||
with patch("pydiscovergy.Discovergy.get_meters") as discovergy:
|
with patch("pydiscovergy.Discovergy.meters") as discovergy:
|
||||||
discovergy.side_effect = AsyncMock(return_value=GET_METERS)
|
discovergy.side_effect = AsyncMock(return_value=GET_METERS)
|
||||||
yield discovergy
|
yield discovergy
|
||||||
|
|
||||||
|
|
|
@ -1,31 +1,34 @@
|
||||||
"""Constants for Discovergy integration tests."""
|
"""Constants for Discovergy integration tests."""
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
from pydiscovergy.models import Meter, Reading
|
from pydiscovergy.models import Location, Meter, Reading
|
||||||
|
|
||||||
GET_METERS = [
|
GET_METERS = [
|
||||||
Meter(
|
Meter(
|
||||||
meterId="f8d610b7a8cc4e73939fa33b990ded54",
|
meter_id="f8d610b7a8cc4e73939fa33b990ded54",
|
||||||
serialNumber="abc123",
|
serial_number="abc123",
|
||||||
fullSerialNumber="abc123",
|
full_serial_number="abc123",
|
||||||
type="TST",
|
type="TST",
|
||||||
measurementType="ELECTRICITY",
|
measurement_type="ELECTRICITY",
|
||||||
loadProfileType="SLP",
|
load_profile_type="SLP",
|
||||||
location={
|
location=Location(
|
||||||
"city": "Testhause",
|
zip=12345,
|
||||||
"street": "Teststraße",
|
city="Testhause",
|
||||||
"streetNumber": "1",
|
street="Teststraße",
|
||||||
"country": "Germany",
|
street_number="1",
|
||||||
|
country="Germany",
|
||||||
|
),
|
||||||
|
additional={
|
||||||
|
"manufacturer_id": "TST",
|
||||||
|
"printed_full_serial_number": "abc123",
|
||||||
|
"administration_number": "12345",
|
||||||
|
"scaling_factor": 1,
|
||||||
|
"current_scaling_factor": 1,
|
||||||
|
"voltage_scaling_factor": 1,
|
||||||
|
"internal_meters": 1,
|
||||||
|
"first_measurement_time": 1517569090926,
|
||||||
|
"last_measurement_time": 1678430543742,
|
||||||
},
|
},
|
||||||
manufacturerId="TST",
|
|
||||||
printedFullSerialNumber="abc123",
|
|
||||||
administrationNumber="12345",
|
|
||||||
scalingFactor=1,
|
|
||||||
currentScalingFactor=1,
|
|
||||||
voltageScalingFactor=1,
|
|
||||||
internalMeters=1,
|
|
||||||
firstMeasurementTime=1517569090926,
|
|
||||||
lastMeasurementTime=1678430543742,
|
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ async def test_form_invalid_auth(hass: HomeAssistant) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"pydiscovergy.Discovergy.get_meters",
|
"pydiscovergy.Discovergy.meters",
|
||||||
side_effect=InvalidLogin,
|
side_effect=InvalidLogin,
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
@ -101,7 +101,7 @@ async def test_form_cannot_connect(hass: HomeAssistant) -> None:
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("pydiscovergy.Discovergy.get_meters", side_effect=HTTPError):
|
with patch("pydiscovergy.Discovergy.meters", side_effect=HTTPError):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
|
@ -120,7 +120,7 @@ async def test_form_unknown_exception(hass: HomeAssistant) -> None:
|
||||||
DOMAIN, context={"source": SOURCE_USER}
|
DOMAIN, context={"source": SOURCE_USER}
|
||||||
)
|
)
|
||||||
|
|
||||||
with patch("pydiscovergy.Discovergy.get_meters", side_effect=Exception):
|
with patch("pydiscovergy.Discovergy.meters", side_effect=Exception):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,8 +16,8 @@ async def test_entry_diagnostics(
|
||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test config entry diagnostics."""
|
"""Test config entry diagnostics."""
|
||||||
with patch("pydiscovergy.Discovergy.get_meters", return_value=GET_METERS), patch(
|
with patch("pydiscovergy.Discovergy.meters", return_value=GET_METERS), patch(
|
||||||
"pydiscovergy.Discovergy.get_last_reading", return_value=LAST_READING
|
"pydiscovergy.Discovergy.meter_last_reading", return_value=LAST_READING
|
||||||
):
|
):
|
||||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -43,18 +43,15 @@ async def test_entry_diagnostics(
|
||||||
assert result["meters"] == [
|
assert result["meters"] == [
|
||||||
{
|
{
|
||||||
"additional": {
|
"additional": {
|
||||||
"administrationNumber": REDACTED,
|
"administration_number": REDACTED,
|
||||||
"currentScalingFactor": 1,
|
"current_scaling_factor": 1,
|
||||||
"firstMeasurementTime": 1517569090926,
|
"first_measurement_time": 1517569090926,
|
||||||
"fullSerialNumber": REDACTED,
|
"internal_meters": 1,
|
||||||
"internalMeters": 1,
|
"last_measurement_time": 1678430543742,
|
||||||
"lastMeasurementTime": 1678430543742,
|
"manufacturer_id": "TST",
|
||||||
"loadProfileType": "SLP",
|
"printed_full_serial_number": REDACTED,
|
||||||
"manufacturerId": "TST",
|
"scaling_factor": 1,
|
||||||
"printedFullSerialNumber": REDACTED,
|
"voltage_scaling_factor": 1,
|
||||||
"scalingFactor": 1,
|
|
||||||
"type": "TST",
|
|
||||||
"voltageScalingFactor": 1,
|
|
||||||
},
|
},
|
||||||
"full_serial_number": REDACTED,
|
"full_serial_number": REDACTED,
|
||||||
"load_profile_type": "SLP",
|
"load_profile_type": "SLP",
|
||||||
|
|
Loading…
Reference in New Issue