Refactor EnergyZero tests (#88458)

This commit is contained in:
Franck Nijhof 2023-02-20 03:11:05 +01:00 committed by GitHub
parent 3533e77ec9
commit 037b3ebd26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 938 additions and 191 deletions

View File

@ -0,0 +1,35 @@
# serializer version: 1
# name: test_full_user_flow
FlowResultSnapshot({
'context': dict({
'source': 'user',
'unique_id': 'energyzero',
}),
'data': dict({
}),
'description': None,
'description_placeholders': None,
'flow_id': <ANY>,
'handler': 'energyzero',
'options': dict({
}),
'result': ConfigEntrySnapshot({
'data': dict({
}),
'disabled_by': None,
'domain': 'energyzero',
'entry_id': <ANY>,
'options': dict({
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'title': 'EnergyZero',
'unique_id': 'energyzero',
'version': 1,
}),
'title': 'EnergyZero',
'type': <FlowResultType.CREATE_ENTRY: 'create_entry'>,
'version': 1,
})
# ---

View File

@ -0,0 +1,43 @@
# serializer version: 1
# name: test_diagnostics
dict({
'energy': dict({
'average_price': 0.37,
'current_hour_price': 0.49,
'highest_price_time': '2022-12-07T16:00:00+00:00',
'lowest_price_time': '2022-12-07T02:00:00+00:00',
'max_price': 0.55,
'min_price': 0.26,
'next_hour_price': 0.55,
'percentage_of_max': 89.09,
}),
'entry': dict({
'title': 'energy',
}),
'gas': dict({
'current_hour_price': 1.47,
'next_hour_price': 1.47,
}),
})
# ---
# name: test_diagnostics_no_gas_today
dict({
'energy': dict({
'average_price': 0.37,
'current_hour_price': 0.49,
'highest_price_time': '2022-12-07T16:00:00+00:00',
'lowest_price_time': '2022-12-07T02:00:00+00:00',
'max_price': 0.55,
'min_price': 0.26,
'next_hour_price': 0.55,
'percentage_of_max': 89.09,
}),
'entry': dict({
'title': 'energy',
}),
'gas': dict({
'current_hour_price': None,
'next_hour_price': None,
}),
})
# ---

View File

@ -0,0 +1,784 @@
# serializer version: 1
# name: test_energy_today
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Current hour',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_current_hour_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.49',
})
# ---
# name: test_energy_today.1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_current_hour_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Current hour',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_energy_today.2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_average_price-today_energy_average_price-]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Average - today',
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_average_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.37',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_average_price-today_energy_average_price-].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_average_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Average - today',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_average_price-today_energy_average_price-].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_average_price-today_energy_average_price-today_energy]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Average - today',
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_average_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.37',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_average_price-today_energy_average_price-today_energy].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_average_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Average - today',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_average_price-today_energy_average_price-today_energy].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Current hour',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_current_hour_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.49',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_current_hour_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Current hour',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-today_energy]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Current hour',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_current_hour_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.49',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-today_energy].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_current_hour_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Current hour',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-today_energy].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_highest_price_time-today_energy_highest_price_time-today_energy]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'device_class': 'timestamp',
'friendly_name': 'Energy market price Time of highest price - today',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_highest_price_time',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '2022-12-07T16:00:00+00:00',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_highest_price_time-today_energy_highest_price_time-today_energy].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_highest_price_time',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'original_icon': None,
'original_name': 'Time of highest price - today',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_highest_price_time-today_energy_highest_price_time-today_energy].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_max_price-today_energy_max_price-today_energy]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Highest price - today',
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_max_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.55',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_max_price-today_energy_max_price-today_energy].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_max_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Highest price - today',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_energy_today[sensor.energyzero_today_energy_max_price-today_energy_max_price-today_energy].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_average_price-today_energy_average_price-today_energy]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Average - today',
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_average_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.37',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_average_price-today_energy_average_price-today_energy].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_average_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Average - today',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_average_price-today_energy_average_price-today_energy].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-today_energy]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Current hour',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_current_hour_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.49',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-today_energy].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_current_hour_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Current hour',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_current_hour_price-today_energy_current_hour_price-today_energy].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_highest_price_time-today_energy_highest_price_time-today_energy]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'device_class': 'timestamp',
'friendly_name': 'Energy market price Time of highest price - today',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_highest_price_time',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '2022-12-07T16:00:00+00:00',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_highest_price_time-today_energy_highest_price_time-today_energy].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_highest_price_time',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TIMESTAMP: 'timestamp'>,
'original_icon': None,
'original_name': 'Time of highest price - today',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': None,
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_highest_price_time-today_energy_highest_price_time-today_energy].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_max_price-today_energy_max_price-today_energy]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Energy market price Highest price - today',
'unit_of_measurement': '€/kWh',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_energy_max_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0.55',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_max_price-today_energy_max_price-today_energy].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_energy_max_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Highest price - today',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/kWh',
})
# ---
# name: test_sensor[sensor.energyzero_today_energy_max_price-today_energy_max_price-today_energy].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Energy market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---
# name: test_sensor[sensor.energyzero_today_gas_current_hour_price-today_gas_current_hour_price-today_gas]
StateSnapshot({
'attributes': ReadOnlyDict({
'attribution': 'Data provided by EnergyZero',
'friendly_name': 'Gas market price Current hour',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': '€/m³',
}),
'context': <ANY>,
'entity_id': 'sensor.energyzero_today_gas_current_hour_price',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '1.47',
})
# ---
# name: test_sensor[sensor.energyzero_today_gas_current_hour_price-today_gas_current_hour_price-today_gas].1
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.energyzero_today_gas_current_hour_price',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'Current hour',
'platform': 'energyzero',
'supported_features': 0,
'translation_key': None,
'unit_of_measurement': '€/m³',
})
# ---
# name: test_sensor[sensor.energyzero_today_gas_current_hour_price-today_gas_current_hour_price-today_gas].2
DeviceRegistryEntrySnapshot({
'area_id': None,
'config_entries': <ANY>,
'configuration_url': None,
'connections': set({
}),
'disabled_by': None,
'entry_type': <DeviceEntryType.SERVICE: 'service'>,
'hw_version': None,
'id': <ANY>,
'is_new': False,
'manufacturer': 'EnergyZero',
'model': None,
'name': 'Gas market price',
'name_by_user': None,
'suggested_area': None,
'sw_version': None,
'via_device_id': None,
})
# ---

View File

@ -1,6 +1,8 @@
"""Test the EnergyZero config flow.""" """Test the EnergyZero config flow."""
from unittest.mock import MagicMock from unittest.mock import MagicMock
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.energyzero.const import DOMAIN from homeassistant.components.energyzero.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -10,6 +12,7 @@ from homeassistant.data_entry_flow import FlowResultType
async def test_full_user_flow( async def test_full_user_flow(
hass: HomeAssistant, hass: HomeAssistant,
mock_setup_entry: MagicMock, mock_setup_entry: MagicMock,
snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test the full user configuration flow.""" """Test the full user configuration flow."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
@ -26,7 +29,6 @@ async def test_full_user_flow(
) )
assert result2.get("type") == FlowResultType.CREATE_ENTRY assert result2.get("type") == FlowResultType.CREATE_ENTRY
assert result2.get("title") == "EnergyZero" assert result2 == snapshot
assert result2.get("data") == {}
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1

View File

@ -3,6 +3,7 @@ from unittest.mock import MagicMock
from energyzero import EnergyZeroNoDataError from energyzero import EnergyZeroNoDataError
import pytest import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.homeassistant import SERVICE_UPDATE_ENTITY from homeassistant.components.homeassistant import SERVICE_UPDATE_ENTITY
from homeassistant.const import ATTR_ENTITY_ID from homeassistant.const import ATTR_ENTITY_ID
@ -13,43 +14,28 @@ from tests.common import MockConfigEntry
from tests.components.diagnostics import get_diagnostics_for_config_entry from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator from tests.typing import ClientSessionGenerator
pytestmark = pytest.mark.freeze_time("2022-12-07 15:00:00")
@pytest.mark.freeze_time("2022-12-07 15:00:00")
async def test_diagnostics( async def test_diagnostics(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
init_integration: MockConfigEntry, init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test diagnostics.""" """Test diagnostics."""
assert await get_diagnostics_for_config_entry( assert (
hass, hass_client, init_integration await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
) == { == snapshot
"entry": { )
"title": "energy",
},
"energy": {
"current_hour_price": 0.49,
"next_hour_price": 0.55,
"average_price": 0.37,
"max_price": 0.55,
"min_price": 0.26,
"highest_price_time": "2022-12-07T16:00:00+00:00",
"lowest_price_time": "2022-12-07T02:00:00+00:00",
"percentage_of_max": 89.09,
},
"gas": {
"current_hour_price": 1.47,
"next_hour_price": 1.47,
},
}
@pytest.mark.freeze_time("2022-12-07 15:00:00")
async def test_diagnostics_no_gas_today( async def test_diagnostics_no_gas_today(
hass: HomeAssistant, hass: HomeAssistant,
hass_client: ClientSessionGenerator, hass_client: ClientSessionGenerator,
mock_energyzero: MagicMock, mock_energyzero: MagicMock,
init_integration: MockConfigEntry, init_integration: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None: ) -> None:
"""Test diagnostics, no gas sensors available.""" """Test diagnostics, no gas sensors available."""
await async_setup_component(hass, "homeassistant", {}) await async_setup_component(hass, "homeassistant", {})
@ -63,24 +49,7 @@ async def test_diagnostics_no_gas_today(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert await get_diagnostics_for_config_entry( assert (
hass, hass_client, init_integration await get_diagnostics_for_config_entry(hass, hass_client, init_integration)
) == { == snapshot
"entry": { )
"title": "energy",
},
"energy": {
"current_hour_price": 0.49,
"next_hour_price": 0.55,
"average_price": 0.37,
"max_price": 0.55,
"min_price": 0.26,
"highest_price_time": "2022-12-07T16:00:00+00:00",
"lowest_price_time": "2022-12-07T02:00:00+00:00",
"percentage_of_max": 89.09,
},
"gas": {
"current_hour_price": None,
"next_hour_price": None,
},
}

View File

@ -2,6 +2,7 @@
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from energyzero import EnergyZeroConnectionError from energyzero import EnergyZeroConnectionError
import pytest
from homeassistant.components.energyzero.const import DOMAIN from homeassistant.components.energyzero.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
@ -10,8 +11,9 @@ from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@pytest.mark.usefixtures("mock_energyzero")
async def test_load_unload_config_entry( async def test_load_unload_config_entry(
hass: HomeAssistant, mock_config_entry: MockConfigEntry, mock_energyzero: MagicMock hass: HomeAssistant, mock_config_entry: MockConfigEntry
) -> None: ) -> None:
"""Test the EnergyZero configuration entry loading/unloading.""" """Test the EnergyZero configuration entry loading/unloading."""
mock_config_entry.add_to_hass(hass) mock_config_entry.add_to_hass(hass)

View File

@ -4,164 +4,77 @@ from unittest.mock import MagicMock
from energyzero import EnergyZeroNoDataError from energyzero import EnergyZeroNoDataError
import pytest import pytest
from syrupy.assertion import SnapshotAssertion
from syrupy.filters import props
from homeassistant.components.energyzero.const import DOMAIN from homeassistant.components.energyzero.const import DOMAIN
from homeassistant.components.homeassistant import SERVICE_UPDATE_ENTITY from homeassistant.components.homeassistant import SERVICE_UPDATE_ENTITY
from homeassistant.components.sensor import ( from homeassistant.const import ATTR_ENTITY_ID, STATE_UNKNOWN
ATTR_STATE_CLASS,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_ENTITY_ID,
ATTR_FRIENDLY_NAME,
ATTR_ICON,
ATTR_UNIT_OF_MEASUREMENT,
CURRENCY_EURO,
STATE_UNKNOWN,
UnitOfEnergy,
UnitOfVolume,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
pytestmark = [pytest.mark.freeze_time("2022-12-07 15:00:00")]
@pytest.mark.freeze_time("2022-12-07 15:00:00")
async def test_energy_today( @pytest.mark.parametrize(
hass: HomeAssistant, init_integration: MockConfigEntry ("entity_id", "entity_unique_id", "device_identifier"),
[
(
"sensor.energyzero_today_energy_current_hour_price",
"today_energy_current_hour_price",
"today_energy",
),
(
"sensor.energyzero_today_energy_average_price",
"today_energy_average_price",
"today_energy",
),
(
"sensor.energyzero_today_energy_max_price",
"today_energy_max_price",
"today_energy",
),
(
"sensor.energyzero_today_energy_highest_price_time",
"today_energy_highest_price_time",
"today_energy",
),
(
"sensor.energyzero_today_gas_current_hour_price",
"today_gas_current_hour_price",
"today_gas",
),
],
)
async def test_sensor(
hass: HomeAssistant,
init_integration: MockConfigEntry,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
entity_id: str,
entity_unique_id: str,
device_identifier: str,
) -> None: ) -> None:
"""Test the EnergyZero - Energy sensors.""" """Test the EnergyZero - Energy sensors."""
entry_id = init_integration.entry_id entry_id = init_integration.entry_id
entity_registry = er.async_get(hass) assert (state := hass.states.get(entity_id))
device_registry = dr.async_get(hass) assert state == snapshot
assert (entity_entry := entity_registry.async_get(entity_id))
assert entity_entry == snapshot(exclude=props("unique_id"))
assert entity_entry.unique_id == f"{entry_id}_{entity_unique_id}"
# Current energy price sensor assert entity_entry.device_id
state = hass.states.get("sensor.energyzero_today_energy_current_hour_price") assert (device_entry := device_registry.async_get(entity_entry.device_id))
entry = entity_registry.async_get( assert device_entry == snapshot(exclude=props("identifiers"))
"sensor.energyzero_today_energy_current_hour_price" assert device_entry.identifiers == {(DOMAIN, f"{entry_id}_{device_identifier}")}
)
assert entry
assert state
assert entry.unique_id == f"{entry_id}_today_energy_current_hour_price"
assert state.state == "0.49"
assert (
state.attributes.get(ATTR_FRIENDLY_NAME) == "Energy market price Current hour"
)
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}"
)
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert ATTR_DEVICE_CLASS not in state.attributes
assert ATTR_ICON not in state.attributes
# Average price sensor
state = hass.states.get("sensor.energyzero_today_energy_average_price")
entry = entity_registry.async_get("sensor.energyzero_today_energy_average_price")
assert entry
assert state
assert entry.unique_id == f"{entry_id}_today_energy_average_price"
assert state.state == "0.37"
assert (
state.attributes.get(ATTR_FRIENDLY_NAME)
== "Energy market price Average - today"
)
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}"
)
assert ATTR_DEVICE_CLASS not in state.attributes
assert ATTR_ICON not in state.attributes
# Highest price sensor
state = hass.states.get("sensor.energyzero_today_energy_max_price")
entry = entity_registry.async_get("sensor.energyzero_today_energy_max_price")
assert entry
assert state
assert entry.unique_id == f"{entry_id}_today_energy_max_price"
assert state.state == "0.55"
assert (
state.attributes.get(ATTR_FRIENDLY_NAME)
== "Energy market price Highest price - today"
)
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== f"{CURRENCY_EURO}/{UnitOfEnergy.KILO_WATT_HOUR}"
)
assert ATTR_DEVICE_CLASS not in state.attributes
assert ATTR_ICON not in state.attributes
# Highest price time sensor
state = hass.states.get("sensor.energyzero_today_energy_highest_price_time")
entry = entity_registry.async_get(
"sensor.energyzero_today_energy_highest_price_time"
)
assert entry
assert state
assert entry.unique_id == f"{entry_id}_today_energy_highest_price_time"
assert state.state == "2022-12-07T16:00:00+00:00"
assert (
state.attributes.get(ATTR_FRIENDLY_NAME)
== "Energy market price Time of highest price - today"
)
assert state.attributes.get(ATTR_DEVICE_CLASS) == SensorDeviceClass.TIMESTAMP
assert ATTR_ICON not in state.attributes
assert entry.device_id
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.identifiers == {(DOMAIN, f"{entry_id}_today_energy")}
assert device_entry.manufacturer == "EnergyZero"
assert device_entry.name == "Energy market price"
assert device_entry.entry_type is dr.DeviceEntryType.SERVICE
assert not device_entry.model
assert not device_entry.sw_version
@pytest.mark.freeze_time("2022-12-07 15:00:00") @pytest.mark.usefixtures("init_integration")
async def test_gas_today( async def test_no_gas_today(hass: HomeAssistant, mock_energyzero: MagicMock) -> None:
hass: HomeAssistant, init_integration: MockConfigEntry
) -> None:
"""Test the EnergyZero - Gas sensors."""
entry_id = init_integration.entry_id
entity_registry = er.async_get(hass)
device_registry = dr.async_get(hass)
# Current gas price sensor
state = hass.states.get("sensor.energyzero_today_gas_current_hour_price")
entry = entity_registry.async_get("sensor.energyzero_today_gas_current_hour_price")
assert entry
assert state
assert entry.unique_id == f"{entry_id}_today_gas_current_hour_price"
assert state.state == "1.47"
assert state.attributes.get(ATTR_FRIENDLY_NAME) == "Gas market price Current hour"
assert (
state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
== f"{CURRENCY_EURO}/{UnitOfVolume.CUBIC_METERS}"
)
assert state.attributes.get(ATTR_STATE_CLASS) == SensorStateClass.MEASUREMENT
assert ATTR_DEVICE_CLASS not in state.attributes
assert ATTR_ICON not in state.attributes
assert entry.device_id
device_entry = device_registry.async_get(entry.device_id)
assert device_entry
assert device_entry.identifiers == {(DOMAIN, f"{entry_id}_today_gas")}
assert device_entry.manufacturer == "EnergyZero"
assert device_entry.name == "Gas market price"
assert device_entry.entry_type is dr.DeviceEntryType.SERVICE
assert not device_entry.model
assert not device_entry.sw_version
@pytest.mark.freeze_time("2022-12-07 15:00:00")
async def test_no_gas_today(
hass: HomeAssistant, mock_energyzero: MagicMock, init_integration: MockConfigEntry
) -> None:
"""Test the EnergyZero - No gas sensors available.""" """Test the EnergyZero - No gas sensors available."""
await async_setup_component(hass, "homeassistant", {}) await async_setup_component(hass, "homeassistant", {})
@ -175,6 +88,5 @@ async def test_no_gas_today(
) )
await hass.async_block_till_done() await hass.async_block_till_done()
state = hass.states.get("sensor.energyzero_today_gas_current_hour_price") assert (state := hass.states.get("sensor.energyzero_today_gas_current_hour_price"))
assert state
assert state.state == STATE_UNKNOWN assert state.state == STATE_UNKNOWN