Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/knx/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)

Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/smart_meter_texas/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions tests/components/homeassistant_hardware/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,13 @@ 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),
]

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),
]

Expand Down Expand Up @@ -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),
]

Expand Down Expand Up @@ -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),
]
39 changes: 38 additions & 1 deletion tests/components/knx/test_sensor.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""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
from homeassistant.core import HomeAssistant

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:
Expand Down Expand Up @@ -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."""

Expand Down
9 changes: 6 additions & 3 deletions tests/components/roborock/test_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading