mirror of
https://github.com/home-assistant/core.git
synced 2026-09-24 07:25:52 -05:00
Add support for gas meter in Powerfox integration (#158196)
Co-authored-by: Joostlek <joostlek@outlook.com>
This commit is contained in:
co-authored by
Joostlek
parent
47e91bc2ec
commit
8d376027bf
@@ -4,7 +4,15 @@ from collections.abc import Generator
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from powerfox import Device, DeviceType, HeatMeter, PowerMeter, WaterMeter
|
||||
from powerfox import (
|
||||
Device,
|
||||
DeviceReport,
|
||||
DeviceType,
|
||||
GasReport,
|
||||
HeatMeter,
|
||||
PowerMeter,
|
||||
WaterMeter,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.powerfox.const import DOMAIN
|
||||
@@ -13,6 +21,64 @@ from homeassistant.const import CONF_EMAIL, CONF_PASSWORD
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
def _power_meter() -> PowerMeter:
|
||||
"""Return a mocked power meter reading."""
|
||||
return PowerMeter(
|
||||
outdated=False,
|
||||
timestamp=datetime(2024, 11, 26, 10, 48, 51, tzinfo=UTC),
|
||||
power=111,
|
||||
energy_usage=1111.111,
|
||||
energy_return=111.111,
|
||||
energy_usage_high_tariff=111.111,
|
||||
energy_usage_low_tariff=111.111,
|
||||
)
|
||||
|
||||
|
||||
def _water_meter() -> WaterMeter:
|
||||
"""Return a mocked water meter reading."""
|
||||
return WaterMeter(
|
||||
outdated=False,
|
||||
timestamp=datetime(2024, 11, 26, 10, 48, 51, tzinfo=UTC),
|
||||
cold_water=1111.111,
|
||||
warm_water=0.0,
|
||||
)
|
||||
|
||||
|
||||
def _heat_meter() -> HeatMeter:
|
||||
"""Return a mocked heat meter reading."""
|
||||
return HeatMeter(
|
||||
outdated=False,
|
||||
timestamp=datetime(2024, 11, 26, 10, 48, 51, tzinfo=UTC),
|
||||
total_energy=1111.111,
|
||||
delta_energy=111,
|
||||
total_volume=1111.111,
|
||||
delta_volume=0.111,
|
||||
)
|
||||
|
||||
|
||||
def _gas_report() -> DeviceReport:
|
||||
"""Return a mocked gas report."""
|
||||
return DeviceReport(
|
||||
gas=GasReport(
|
||||
total_delta=100,
|
||||
sum=10.5,
|
||||
total_delta_currency=5.0,
|
||||
current_consumption=0.4,
|
||||
current_consumption_kwh=4.0,
|
||||
consumption=10.5,
|
||||
consumption_kwh=10.5,
|
||||
max_consumption=1.5,
|
||||
min_consumption=0.2,
|
||||
avg_consumption=0.6,
|
||||
max_consumption_kwh=1.7,
|
||||
min_consumption_kwh=0.1,
|
||||
avg_consumption_kwh=0.5,
|
||||
sum_currency=2.5,
|
||||
max_currency=0.3,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Override async_setup_entry."""
|
||||
@@ -61,32 +127,25 @@ def mock_powerfox_client() -> Generator[AsyncMock]:
|
||||
type=DeviceType.HEAT_METER,
|
||||
name="Heatopti",
|
||||
),
|
||||
]
|
||||
client.device.side_effect = [
|
||||
PowerMeter(
|
||||
outdated=False,
|
||||
timestamp=datetime(2024, 11, 26, 10, 48, 51, tzinfo=UTC),
|
||||
power=111,
|
||||
energy_usage=1111.111,
|
||||
energy_return=111.111,
|
||||
energy_usage_high_tariff=111.111,
|
||||
energy_usage_low_tariff=111.111,
|
||||
),
|
||||
WaterMeter(
|
||||
outdated=False,
|
||||
timestamp=datetime(2024, 11, 26, 10, 48, 51, tzinfo=UTC),
|
||||
cold_water=1111.111,
|
||||
warm_water=0.0,
|
||||
),
|
||||
HeatMeter(
|
||||
outdated=False,
|
||||
timestamp=datetime(2024, 11, 26, 10, 48, 51, tzinfo=UTC),
|
||||
total_energy=1111.111,
|
||||
delta_energy=111,
|
||||
total_volume=1111.111,
|
||||
delta_volume=0.111,
|
||||
Device(
|
||||
id="9x9x1f12xx6x",
|
||||
date_added=datetime(2024, 11, 26, 9, 22, 35, tzinfo=UTC),
|
||||
main_device=False,
|
||||
bidirectional=False,
|
||||
type=DeviceType.GAS_METER,
|
||||
name="Gasopti",
|
||||
),
|
||||
]
|
||||
device_factories = {
|
||||
"9x9x1f12xx3x": _power_meter,
|
||||
"9x9x1f12xx4x": _water_meter,
|
||||
"9x9x1f12xx5x": _heat_meter,
|
||||
}
|
||||
|
||||
client.device = AsyncMock(
|
||||
side_effect=lambda *, device_id: device_factories[device_id]() # type: ignore[index]
|
||||
)
|
||||
client.report = AsyncMock(return_value=_gas_report())
|
||||
yield client
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,16 @@
|
||||
'total_volume': 1111.111,
|
||||
}),
|
||||
}),
|
||||
dict({
|
||||
'gas_meter': dict({
|
||||
'consumption': 10.5,
|
||||
'consumption_kwh': 10.5,
|
||||
'current_consumption': 0.4,
|
||||
'current_consumption_kwh': 4.0,
|
||||
'sum': 10.5,
|
||||
'sum_currency': 2.5,
|
||||
}),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
# ---
|
||||
|
||||
@@ -1,4 +1,649 @@
|
||||
# serializer version: 1
|
||||
# name: test_all_sensors[sensor.gasopti_avg_gas_hourly_consumption_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_avg_gas_hourly_consumption_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.GAS: 'gas'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Avg gas hourly consumption - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_avg_consumption_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_avg_consumption_today',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_avg_gas_hourly_consumption_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'gas',
|
||||
'friendly_name': 'Gasopti Avg gas hourly consumption - today',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_avg_gas_hourly_consumption_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0.6',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_avg_gas_hourly_energy_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_avg_gas_hourly_energy_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Avg gas hourly energy - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_avg_consumption_energy_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_avg_consumption_energy_today',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_avg_gas_hourly_energy_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'energy',
|
||||
'friendly_name': 'Gasopti Avg gas hourly energy - today',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_avg_gas_hourly_energy_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0.5',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_consumption_energy_this_hour-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_gas_consumption_energy_this_hour',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Gas consumption energy - this hour',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_current_consumption_energy',
|
||||
'unique_id': '9x9x1f12xx6x_gas_current_consumption_energy',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_consumption_energy_this_hour-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'energy',
|
||||
'friendly_name': 'Gasopti Gas consumption energy - this hour',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_gas_consumption_energy_this_hour',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '4.0',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_consumption_energy_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_gas_consumption_energy_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Gas consumption energy - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_consumption_energy_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_consumption_energy_today',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_consumption_energy_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'energy',
|
||||
'friendly_name': 'Gasopti Gas consumption energy - today',
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_gas_consumption_energy_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '10.5',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_consumption_this_hour-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_gas_consumption_this_hour',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.GAS: 'gas'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Gas consumption - this hour',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_current_consumption',
|
||||
'unique_id': '9x9x1f12xx6x_gas_current_consumption',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_consumption_this_hour-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'gas',
|
||||
'friendly_name': 'Gasopti Gas consumption - this hour',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_gas_consumption_this_hour',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0.4',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_consumption_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_gas_consumption_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.GAS: 'gas'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Gas consumption - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_consumption_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_consumption_today',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_consumption_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'gas',
|
||||
'friendly_name': 'Gasopti Gas consumption - today',
|
||||
'state_class': <SensorStateClass.TOTAL_INCREASING: 'total_increasing'>,
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_gas_consumption_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '10.5',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_cost_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': dict({
|
||||
'state_class': <SensorStateClass.TOTAL: 'total'>,
|
||||
}),
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_gas_cost_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Gas cost - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_cost_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_cost_today',
|
||||
'unit_of_measurement': '€',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_gas_cost_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'monetary',
|
||||
'friendly_name': 'Gasopti Gas cost - today',
|
||||
'state_class': <SensorStateClass.TOTAL: 'total'>,
|
||||
'unit_of_measurement': '€',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_gas_cost_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '2.5',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_max_gas_hourly_consumption_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_max_gas_hourly_consumption_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.GAS: 'gas'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Max gas hourly consumption - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_max_consumption_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_max_consumption_today',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_max_gas_hourly_consumption_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'gas',
|
||||
'friendly_name': 'Gasopti Max gas hourly consumption - today',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_max_gas_hourly_consumption_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '1.5',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_max_gas_hourly_cost_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_max_gas_hourly_cost_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.MONETARY: 'monetary'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Max gas hourly cost - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_max_cost_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_max_cost_today',
|
||||
'unit_of_measurement': '€',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_max_gas_hourly_cost_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'monetary',
|
||||
'friendly_name': 'Gasopti Max gas hourly cost - today',
|
||||
'unit_of_measurement': '€',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_max_gas_hourly_cost_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0.3',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_max_gas_hourly_energy_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_max_gas_hourly_energy_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Max gas hourly energy - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_max_consumption_energy_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_max_consumption_energy_today',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_max_gas_hourly_energy_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'energy',
|
||||
'friendly_name': 'Gasopti Max gas hourly energy - today',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_max_gas_hourly_energy_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '1.7',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_min_gas_hourly_consumption_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_min_gas_hourly_consumption_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.GAS: 'gas'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Min gas hourly consumption - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_min_consumption_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_min_consumption_today',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_min_gas_hourly_consumption_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'gas',
|
||||
'friendly_name': 'Gasopti Min gas hourly consumption - today',
|
||||
'unit_of_measurement': <UnitOfVolume.CUBIC_METERS: 'm³'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_min_gas_hourly_consumption_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0.2',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_min_gas_hourly_energy_today-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'sensor',
|
||||
'entity_category': None,
|
||||
'entity_id': 'sensor.gasopti_min_gas_hourly_energy_today',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'options': dict({
|
||||
'sensor': dict({
|
||||
'suggested_display_precision': 2,
|
||||
}),
|
||||
}),
|
||||
'original_device_class': <SensorDeviceClass.ENERGY: 'energy'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Min gas hourly energy - today',
|
||||
'platform': 'powerfox',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'gas_min_consumption_energy_today',
|
||||
'unique_id': '9x9x1f12xx6x_gas_min_consumption_energy_today',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.gasopti_min_gas_hourly_energy_today-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'energy',
|
||||
'friendly_name': 'Gasopti Min gas hourly energy - today',
|
||||
'unit_of_measurement': <UnitOfEnergy.KILO_WATT_HOUR: 'kWh'>,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'sensor.gasopti_min_gas_hourly_energy_today',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': '0.1',
|
||||
})
|
||||
# ---
|
||||
# name: test_all_sensors[sensor.heatopti_delta_energy-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
|
||||
@@ -6,7 +6,8 @@ from datetime import timedelta
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from powerfox import PowerfoxConnectionError
|
||||
from powerfox import DeviceReport, PowerfoxConnectionError
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
@@ -19,6 +20,7 @@ from . import setup_integration
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed, snapshot_platform
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_all_sensors(
|
||||
hass: HomeAssistant,
|
||||
mock_powerfox_client: AsyncMock,
|
||||
@@ -51,3 +53,17 @@ async def test_update_failed(
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get("sensor.poweropti_energy_usage").state == STATE_UNAVAILABLE
|
||||
|
||||
|
||||
async def test_skips_gas_sensors_when_report_missing(
|
||||
hass: HomeAssistant,
|
||||
mock_powerfox_client: AsyncMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
) -> None:
|
||||
"""Test gas sensors are not created when report lacks gas data."""
|
||||
mock_powerfox_client.report.return_value = DeviceReport(gas=None)
|
||||
|
||||
with patch("homeassistant.components.powerfox.PLATFORMS", [Platform.SENSOR]):
|
||||
await setup_integration(hass, mock_config_entry)
|
||||
|
||||
assert hass.states.get("sensor.gasopti_gas_consumption_today") is None
|
||||
|
||||
Reference in New Issue
Block a user