"""Tests for 1-Wire binary sensors.""" from collections.abc import Generator from unittest.mock import MagicMock, patch import pytest from syrupy.assertion import SnapshotAssertion from homeassistant.config_entries import ConfigEntry from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import device_registry as dr, entity_registry as er from . import setup_owproxy_mock_devices @pytest.fixture(autouse=True) def override_platforms() -> Generator[None]: """Override PLATFORMS.""" with patch("homeassistant.components.onewire.PLATFORMS", [Platform.BINARY_SENSOR]): yield async def test_binary_sensors( hass: HomeAssistant, config_entry: ConfigEntry, owproxy: MagicMock, device_id: str, device_registry: dr.DeviceRegistry, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion, ) -> None: """Test for 1-Wire binary sensors.""" setup_owproxy_mock_devices(owproxy, Platform.BINARY_SENSOR, [device_id]) await hass.config_entries.async_setup(config_entry.entry_id) await hass.async_block_till_done() # Ensure devices are correctly registered device_entries = dr.async_entries_for_config_entry( device_registry, config_entry.entry_id ) assert device_entries == snapshot # Ensure entities are correctly registered entity_entries = er.async_entries_for_config_entry( entity_registry, config_entry.entry_id ) assert entity_entries == snapshot setup_owproxy_mock_devices(owproxy, Platform.BINARY_SENSOR, [device_id]) # Some entities are disabled, enable them and reload before checking states for ent in entity_entries: entity_registry.async_update_entity(ent.entity_id, disabled_by=None) await hass.config_entries.async_reload(config_entry.entry_id) await hass.async_block_till_done() # Ensure entity states are correct states = [hass.states.get(ent.entity_id) for ent in entity_entries] assert states == snapshot