From 84b85371b68883be7658ba43b3f678f022355a98 Mon Sep 17 00:00:00 2001 From: th3spis Date: Sun, 29 Mar 2026 17:06:19 +0200 Subject: [PATCH 1/5] Added wfsens as a occupancy source. With the current implementation the occupancy binary sensor is never added. It is supossed to be added the first time that the light is turned on because of the spacesense (expecting "src": "pir"). The bulbs currently notify it using "src": "wfsens" on its push msg, so Homa Assistant doesnt get it right. --- homeassistant/components/wiz/__init__.py | 4 ++-- homeassistant/components/wiz/binary_sensor.py | 4 ++-- homeassistant/components/wiz/const.py | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/wiz/__init__.py b/homeassistant/components/wiz/__init__.py index eae5657589a947..52b6996318587b 100644 --- a/homeassistant/components/wiz/__init__.py +++ b/homeassistant/components/wiz/__init__.py @@ -4,7 +4,6 @@ from typing import Any from pywizlight import PilotParser, wizlight -from pywizlight.bulb import PIR_SOURCE from homeassistant.const import CONF_HOST, EVENT_HOMEASSISTANT_STOP, Platform from homeassistant.core import Event, HomeAssistant, callback @@ -18,6 +17,7 @@ DISCOVER_SCAN_TIMEOUT, DISCOVERY_INTERVAL, DOMAIN, + OCCUPANCY_SOURCES, SIGNAL_WIZ_PIR, WIZ_CONNECT_EXCEPTIONS, ) @@ -99,7 +99,7 @@ def _async_push_update(state: PilotParser) -> None: """Receive a push update.""" _LOGGER.debug("%s: Got push update: %s", bulb.mac, state.pilotResult) coordinator.async_set_updated_data(coordinator.data) - if state.get_source() == PIR_SOURCE: + if state.get_source() in OCCUPANCY_SOURCES: async_dispatcher_send(hass, SIGNAL_WIZ_PIR.format(bulb.mac)) await bulb.start_push(_async_push_update) diff --git a/homeassistant/components/wiz/binary_sensor.py b/homeassistant/components/wiz/binary_sensor.py index 8f1c5ff53a2554..e4036658d71044 100644 --- a/homeassistant/components/wiz/binary_sensor.py +++ b/homeassistant/components/wiz/binary_sensor.py @@ -2,7 +2,7 @@ from collections.abc import Callable -from pywizlight.bulb import PIR_SOURCE +from .const import OCCUPANCY_SOURCES from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, @@ -73,5 +73,5 @@ def __init__(self, wiz_data: WizData, name: str) -> None: @callback def _async_update_attrs(self) -> None: """Handle updating _attr values.""" - if self._device.state.get_source() == PIR_SOURCE: + if self._device.state.get_source() in OCCUPANCY_SOURCES: self._attr_is_on = self._device.status diff --git a/homeassistant/components/wiz/const.py b/homeassistant/components/wiz/const.py index 78074a3d5fbc52..8f203d184f17a5 100644 --- a/homeassistant/components/wiz/const.py +++ b/homeassistant/components/wiz/const.py @@ -24,3 +24,4 @@ WIZ_CONNECT_EXCEPTIONS = (WizLightNotKnownBulb, *WIZ_EXCEPTIONS) SIGNAL_WIZ_PIR = "wiz_pir_{}" +OCCUPANCY_SOURCES = frozenset({"pir", "wfsens"}) From 09e76860833db86824d36b2c9cc4a9e8111ce445 Mon Sep 17 00:00:00 2001 From: th3spis Date: Thu, 2 Apr 2026 17:04:37 +0200 Subject: [PATCH 2/5] Review suggestions --- homeassistant/components/wiz/const.py | 5 ++++- tests/components/wiz/test_binary_sensor.py | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/wiz/const.py b/homeassistant/components/wiz/const.py index 8f203d184f17a5..fc8949c9264b16 100644 --- a/homeassistant/components/wiz/const.py +++ b/homeassistant/components/wiz/const.py @@ -1,6 +1,7 @@ """Constants for the WiZ Platform integration.""" from datetime import timedelta +from pywizlight.bulb import PIR_SOURCE from pywizlight.exceptions import ( WizLightConnectionError, @@ -24,4 +25,6 @@ WIZ_CONNECT_EXCEPTIONS = (WizLightNotKnownBulb, *WIZ_EXCEPTIONS) SIGNAL_WIZ_PIR = "wiz_pir_{}" -OCCUPANCY_SOURCES = frozenset({"pir", "wfsens"}) +OCCUPANCY_SOURCES = frozenset({PIR_SOURCE, "wfsens"}) +# NOTE: When adding to OCCUPANCY_SOURCES (e.g., "wfsens"), ensure tests cover push updates with these sources. +# See: tests/components/wiz/test_xxx.py. Verify that entity creation and update for src="wfsens" behaves the same as for src="pir". \ No newline at end of file diff --git a/tests/components/wiz/test_binary_sensor.py b/tests/components/wiz/test_binary_sensor.py index c7e5541d91ec7f..85705dadfd6b43 100644 --- a/tests/components/wiz/test_binary_sensor.py +++ b/tests/components/wiz/test_binary_sensor.py @@ -1,5 +1,7 @@ """Tests for WiZ binary_sensor platform.""" +import pytest + from homeassistant.components import wiz from homeassistant.components.wiz.binary_sensor import OCCUPANCY_UNIQUE_ID from homeassistant.config_entries import ConfigEntryState @@ -21,20 +23,27 @@ from tests.common import MockConfigEntry +@pytest.mark.parametrize("occupancy_source", ["pir", "wfsens"]) async def test_binary_sensor_created_from_push_updates( - hass: HomeAssistant, entity_registry: er.EntityRegistry + hass: HomeAssistant, + entity_registry: er.EntityRegistry, + occupancy_source: str, ) -> None: """Test a binary sensor created from push updates.""" bulb, _ = await async_setup_integration(hass) - await async_push_update(hass, bulb, {"mac": FAKE_MAC, "src": "pir", "state": True}) + await async_push_update( + hass, bulb, {"mac": FAKE_MAC, "src": occupancy_source, "state": True} + ) entity_id = "binary_sensor.mock_title_occupancy" assert entity_registry.async_get(entity_id).unique_id == f"{FAKE_MAC}_occupancy" state = hass.states.get(entity_id) assert state.state == STATE_ON - await async_push_update(hass, bulb, {"mac": FAKE_MAC, "src": "pir", "state": False}) + await async_push_update( + hass, bulb, {"mac": FAKE_MAC, "src": occupancy_source, "state": False} + ) state = hass.states.get(entity_id) assert state.state == STATE_OFF From f18af57d43d10bd39de41b737f3a12ea4956d809 Mon Sep 17 00:00:00 2001 From: th3spis Date: Thu, 2 Apr 2026 17:41:43 +0200 Subject: [PATCH 3/5] new line at end of file --- homeassistant/components/wiz/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/wiz/const.py b/homeassistant/components/wiz/const.py index fc8949c9264b16..32244b7419ea1f 100644 --- a/homeassistant/components/wiz/const.py +++ b/homeassistant/components/wiz/const.py @@ -27,4 +27,4 @@ SIGNAL_WIZ_PIR = "wiz_pir_{}" OCCUPANCY_SOURCES = frozenset({PIR_SOURCE, "wfsens"}) # NOTE: When adding to OCCUPANCY_SOURCES (e.g., "wfsens"), ensure tests cover push updates with these sources. -# See: tests/components/wiz/test_xxx.py. Verify that entity creation and update for src="wfsens" behaves the same as for src="pir". \ No newline at end of file +# See: tests/components/wiz/test_xxx.py. Verify that entity creation and update for src="wfsens" behaves the same as for src="pir". From 7865e637d96a93ade80ba7226532c601d9110cc9 Mon Sep 17 00:00:00 2001 From: th3spis Date: Wed, 6 May 2026 17:02:32 +0200 Subject: [PATCH 4/5] Remove unnecessary comments from const.py --- homeassistant/components/wiz/binary_sensor.py | 3 +-- homeassistant/components/wiz/const.py | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/wiz/binary_sensor.py b/homeassistant/components/wiz/binary_sensor.py index e4036658d71044..8c24882ce065cb 100644 --- a/homeassistant/components/wiz/binary_sensor.py +++ b/homeassistant/components/wiz/binary_sensor.py @@ -2,7 +2,6 @@ from collections.abc import Callable -from .const import OCCUPANCY_SOURCES from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, @@ -14,7 +13,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from .const import DOMAIN, SIGNAL_WIZ_PIR +from .const import DOMAIN, SIGNAL_WIZ_PIR, OCCUPANCY_SOURCES from .coordinator import WizConfigEntry, WizData from .entity import WizEntity diff --git a/homeassistant/components/wiz/const.py b/homeassistant/components/wiz/const.py index 32244b7419ea1f..59cc7788a74fcc 100644 --- a/homeassistant/components/wiz/const.py +++ b/homeassistant/components/wiz/const.py @@ -1,8 +1,8 @@ """Constants for the WiZ Platform integration.""" from datetime import timedelta -from pywizlight.bulb import PIR_SOURCE +from pywizlight.bulb import PIR_SOURCE from pywizlight.exceptions import ( WizLightConnectionError, WizLightNotKnownBulb, @@ -26,5 +26,3 @@ SIGNAL_WIZ_PIR = "wiz_pir_{}" OCCUPANCY_SOURCES = frozenset({PIR_SOURCE, "wfsens"}) -# NOTE: When adding to OCCUPANCY_SOURCES (e.g., "wfsens"), ensure tests cover push updates with these sources. -# See: tests/components/wiz/test_xxx.py. Verify that entity creation and update for src="wfsens" behaves the same as for src="pir". From c6b7c4e0b13607864b4222d69b73a3db716ca81a Mon Sep 17 00:00:00 2001 From: Joostlek Date: Fri, 8 May 2026 00:01:03 +0200 Subject: [PATCH 5/5] Fix --- homeassistant/components/wiz/binary_sensor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/homeassistant/components/wiz/binary_sensor.py b/homeassistant/components/wiz/binary_sensor.py index 8c24882ce065cb..bcbf6419696e57 100644 --- a/homeassistant/components/wiz/binary_sensor.py +++ b/homeassistant/components/wiz/binary_sensor.py @@ -2,7 +2,6 @@ from collections.abc import Callable - from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, BinarySensorEntity, @@ -13,7 +12,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback -from .const import DOMAIN, SIGNAL_WIZ_PIR, OCCUPANCY_SOURCES +from .const import DOMAIN, OCCUPANCY_SOURCES, SIGNAL_WIZ_PIR from .coordinator import WizConfigEntry, WizData from .entity import WizEntity