diff --git a/homeassistant/components/utility_meter/diagnostics.py b/homeassistant/components/utility_meter/diagnostics.py index 57850beb0fb..1ff723f7a89 100644 --- a/homeassistant/components/utility_meter/diagnostics.py +++ b/homeassistant/components/utility_meter/diagnostics.py @@ -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 } ) diff --git a/homeassistant/components/utility_meter/sensor.py b/homeassistant/components/utility_meter/sensor.py index 96cfccfd211..4a68248f067 100644 --- a/homeassistant/components/utility_meter/sensor.py +++ b/homeassistant/components/utility_meter/sensor.py @@ -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 diff --git a/tests/components/utility_meter/snapshots/test_diagnostics.ambr b/tests/components/utility_meter/snapshots/test_diagnostics.ambr index 9858973d912..28841854766 100644 --- a/tests/components/utility_meter/snapshots/test_diagnostics.ambr +++ b/tests/components/utility_meter/snapshots/test_diagnostics.ambr @@ -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', }), ]), }) diff --git a/tests/components/utility_meter/test_config_flow.py b/tests/components/utility_meter/test_config_flow.py index eccc1d3e12d..560566d7c49 100644 --- a/tests/components/utility_meter/test_config_flow.py +++ b/tests/components/utility_meter/test_config_flow.py @@ -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(