diff --git a/homeassistant/components/knx/sensor.py b/homeassistant/components/knx/sensor.py index e75d1f180e26ec..ccc0d27306f04e 100644 --- a/homeassistant/components/knx/sensor.py +++ b/homeassistant/components/knx/sensor.py @@ -136,7 +136,7 @@ def _create_sensor(xknx: XKNX, config: ConfigType) -> XknxSensor: name=config[CONF_NAME], group_address_state=config[SensorSchema.CONF_STATE_ADDRESS], sync_state=config[SensorSchema.CONF_SYNC_STATE], - always_callback=config[SensorSchema.CONF_ALWAYS_CALLBACK], + always_callback=True, value_type=config[CONF_TYPE], ) @@ -159,7 +159,7 @@ def __init__(self, knx_module: KNXModule, config: ConfigType) -> None: SensorDeviceClass, self._device.ha_device_class() ) - self._attr_force_update = self._device.always_callback + self._attr_force_update = config[SensorSchema.CONF_ALWAYS_CALLBACK] self._attr_entity_category = config.get(CONF_ENTITY_CATEGORY) self._attr_unique_id = str(self._device.sensor_value.group_address_state) self._attr_native_unit_of_measurement = self._device.unit_of_measurement() diff --git a/homeassistant/components/smart_meter_texas/sensor.py b/homeassistant/components/smart_meter_texas/sensor.py index 480188ab2a6440..6099b489c4387e 100644 --- a/homeassistant/components/smart_meter_texas/sensor.py +++ b/homeassistant/components/smart_meter_texas/sensor.py @@ -67,7 +67,7 @@ def extra_state_attributes(self): } @callback - def _state_update(self): + def _handle_coordinator_update(self) -> None: """Call when the coordinator has an update.""" self._attr_available = self.coordinator.last_update_success if self._attr_available: @@ -77,7 +77,6 @@ def _state_update(self): async def async_added_to_hass(self) -> None: """Subscribe to updates.""" await super().async_added_to_hass() - self.async_on_remove(self.coordinator.async_add_listener(self._state_update)) # If the background update finished before # we added the entity, there is no need to restore diff --git a/requirements_test.txt b/requirements_test.txt index 6b5965879ce8a8..3ed5357422570c 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -18,7 +18,7 @@ mock-open==1.4.0 mypy-dev==1.19.0a4 pre-commit==4.2.0 pydantic==2.12.0 -pylint==3.3.8 +pylint==3.3.9 pylint-per-file-ignores==1.4.0 pipdeptree==2.26.1 pytest-asyncio==1.2.0 diff --git a/tests/components/homeassistant_hardware/test_util.py b/tests/components/homeassistant_hardware/test_util.py index 94cac924683238..ef064ba4195baf 100644 --- a/tests/components/homeassistant_hardware/test_util.py +++ b/tests/components/homeassistant_hardware/test_util.py @@ -612,7 +612,6 @@ async def mock_flash_firmware( call(hass), # pylint: disable-next=unnecessary-dunder-call call().__aenter__(ANY), - # pylint: disable-next=unnecessary-dunder-call call().__aexit__(ANY, None, None, None), ] @@ -620,7 +619,6 @@ async def mock_flash_firmware( call(hass), # pylint: disable-next=unnecessary-dunder-call call().__aenter__(ANY), - # pylint: disable-next=unnecessary-dunder-call call().__aexit__(ANY, None, None, None), ] @@ -669,14 +667,12 @@ async def test_async_flash_silabs_firmware_flash_failure(hass: HomeAssistant) -> call(hass), # pylint: disable-next=unnecessary-dunder-call call().__aenter__(ANY), - # pylint: disable-next=unnecessary-dunder-call call().__aexit__(ANY, HomeAssistantError, exc.value, ANY), ] assert owner2.temporarily_stop.mock_calls == [ call(hass), # pylint: disable-next=unnecessary-dunder-call call().__aenter__(ANY), - # pylint: disable-next=unnecessary-dunder-call call().__aexit__(ANY, HomeAssistantError, exc.value, ANY), ] @@ -731,13 +727,11 @@ async def test_async_flash_silabs_firmware_probe_failure(hass: HomeAssistant) -> call(hass), # pylint: disable-next=unnecessary-dunder-call call().__aenter__(ANY), - # pylint: disable-next=unnecessary-dunder-call call().__aexit__(ANY, None, None, None), ] assert owner2.temporarily_stop.mock_calls == [ call(hass), # pylint: disable-next=unnecessary-dunder-call call().__aenter__(ANY), - # pylint: disable-next=unnecessary-dunder-call call().__aexit__(ANY, None, None, None), ] diff --git a/tests/components/knx/test_sensor.py b/tests/components/knx/test_sensor.py index 41ffcfcb5c73c8..26da92e72c9447 100644 --- a/tests/components/knx/test_sensor.py +++ b/tests/components/knx/test_sensor.py @@ -1,5 +1,7 @@ """Test KNX sensor.""" +from freezegun.api import FrozenDateTimeFactory + from homeassistant.components.knx.const import CONF_STATE_ADDRESS, CONF_SYNC_STATE from homeassistant.components.knx.schema import SensorSchema from homeassistant.const import CONF_NAME, CONF_TYPE, STATE_UNKNOWN @@ -7,7 +9,7 @@ from .conftest import KNXTestKit -from tests.common import async_capture_events +from tests.common import async_capture_events, async_fire_time_changed async def test_sensor(hass: HomeAssistant, knx: KNXTestKit) -> None: @@ -41,6 +43,41 @@ async def test_sensor(hass: HomeAssistant, knx: KNXTestKit) -> None: await knx.assert_no_telegram() +async def test_last_reported( + hass: HomeAssistant, + knx: KNXTestKit, + freezer: FrozenDateTimeFactory, +) -> None: + """Test KNX sensor with last_reported.""" + + await knx.setup_integration( + { + SensorSchema.PLATFORM: [ + { + CONF_NAME: "test", + CONF_STATE_ADDRESS: "1/1/1", + CONF_SYNC_STATE: False, + CONF_TYPE: "percentU8", + }, + ] + } + ) + events = async_capture_events(hass, "state_changed") + + # receive initial telegram + await knx.receive_write("1/1/1", (0x42,)) + first_reported = hass.states.get("sensor.test").last_reported + assert len(events) == 1 + + # receive second telegram with identical payload + freezer.tick(1) + async_fire_time_changed(hass) + await knx.receive_write("1/1/1", (0x42,)) + + assert first_reported != hass.states.get("sensor.test").last_reported + assert len(events) == 1, events # last_reported shall not fire state_changed + + async def test_always_callback(hass: HomeAssistant, knx: KNXTestKit) -> None: """Test KNX sensor with always_callback.""" diff --git a/tests/components/roborock/test_coordinator.py b/tests/components/roborock/test_coordinator.py index 315ab14bdb5042..77b5f9bfa29e30 100644 --- a/tests/components/roborock/test_coordinator.py +++ b/tests/components/roborock/test_coordinator.py @@ -92,9 +92,12 @@ async def test_visible_background( await hass.config_entries.async_setup(mock_roborock_entry.entry_id) await hass.async_block_till_done() coordinator: RoborockDataUpdateCoordinator = mock_roborock_entry.runtime_data.v1[0] - assert coordinator.map_parser._palette.get_color( # pylint: disable=protected-access - SupportedColor.MAP_OUTSIDE - ) != (0, 0, 0, 0) + assert coordinator.map_parser._palette.get_color(SupportedColor.MAP_OUTSIDE) != ( + 0, + 0, + 0, + 0, + ) @pytest.mark.parametrize(