Moves diagnostic information from attributes to diagnostic in Utility Meter (#118637)

* move diag information from attributes to diagnostic

* remove constant attributes

---------

Co-authored-by: G Johansson <goran.johansson@shiftit.se>
This commit is contained in:
Diogo Gomes 2024-06-15 11:50:19 +01:00 committed by GitHub
parent dac661831e
commit 8cf1890772
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 14 deletions

View File

@ -26,6 +26,9 @@ async def async_get_config_entry_diagnostics(
"entity_id": sensor.entity_id,
"extra_attributes": sensor.extra_state_attributes,
"last_sensor_data": restored_last_extra_data,
"period": sensor._period, # noqa: SLF001
"cron": sensor._cron_pattern, # noqa: SLF001
"source": sensor._sensor_source_id, # noqa: SLF001
}
)

View File

@ -57,7 +57,6 @@ import homeassistant.util.dt as dt_util
from homeassistant.util.enum import try_parse_enum
from .const import (
ATTR_CRON_PATTERN,
ATTR_NEXT_RESET,
ATTR_VALUE,
BIMONTHLY,
@ -740,15 +739,10 @@ class UtilityMeterSensor(RestoreSensor):
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
state_attr = {
ATTR_SOURCE_ID: self._sensor_source_id,
ATTR_STATUS: PAUSED if self._collecting is None else COLLECTING,
ATTR_LAST_PERIOD: str(self._last_period),
ATTR_LAST_VALID_STATE: str(self._last_valid_state),
}
if self._period is not None:
state_attr[ATTR_PERIOD] = self._period
if self._cron_pattern is not None:
state_attr[ATTR_CRON_PATTERN] = self._cron_pattern
if self._tariff is not None:
state_attr[ATTR_TARIFF] = self._tariff
# last_reset in utility meter was used before last_reset was added for long term

View File

@ -29,36 +29,36 @@
}),
'tariff_sensors': list([
dict({
'cron': '0 0 1 * *',
'entity_id': 'sensor.energy_bill_tariff0',
'extra_attributes': dict({
'cron pattern': '0 0 1 * *',
'last_period': '0',
'last_reset': '2024-04-05T00:00:00+00:00',
'last_valid_state': 'None',
'meter_period': 'monthly',
'next_reset': '2024-05-01T00:00:00-07:00',
'source': 'sensor.input1',
'status': 'collecting',
'tariff': 'tariff0',
}),
'last_sensor_data': None,
'name': 'Energy Bill tariff0',
'period': 'monthly',
'source': 'sensor.input1',
}),
dict({
'cron': '0 0 1 * *',
'entity_id': 'sensor.energy_bill_tariff1',
'extra_attributes': dict({
'cron pattern': '0 0 1 * *',
'last_period': '0',
'last_reset': '2024-04-05T00:00:00+00:00',
'last_valid_state': 'None',
'meter_period': 'monthly',
'next_reset': '2024-05-01T00:00:00-07:00',
'source': 'sensor.input1',
'status': 'paused',
'tariff': 'tariff1',
}),
'last_sensor_data': None,
'name': 'Energy Bill tariff1',
'period': 'monthly',
'source': 'sensor.input1',
}),
]),
})

View File

@ -332,8 +332,6 @@ async def test_options(hass: HomeAssistant) -> None:
# Check config entry is reloaded with new options
await hass.async_block_till_done()
state = hass.states.get("sensor.electricity_meter")
assert state.attributes["source"] == input_sensor2_entity_id
async def test_change_device_source(