Revert "Fix Shelly RPC RSSI sensor removal (#111035)"

This reverts commit 4eb1bac859757c9dcc180e60957a56e2a92b1eb9.
This commit is contained in:
Franck Nijhof 2024-02-22 12:05:24 +01:00
parent c76c66c466
commit 728399c09a
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
4 changed files with 5 additions and 44 deletions

View File

@ -51,11 +51,7 @@ from .entity import (
async_setup_entry_rest, async_setup_entry_rest,
async_setup_entry_rpc, async_setup_entry_rpc,
) )
from .utils import ( from .utils import get_device_entry_gen, get_device_uptime
get_device_entry_gen,
get_device_uptime,
is_rpc_wifi_stations_disabled,
)
@dataclass(frozen=True) @dataclass(frozen=True)
@ -911,7 +907,9 @@ RPC_SENSORS: Final = {
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
removal_condition=is_rpc_wifi_stations_disabled, removal_condition=lambda config, _status, key: (
config[key]["sta"]["enable"] is False
),
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
use_polling_coordinator=True, use_polling_coordinator=True,
), ),

View File

@ -447,13 +447,3 @@ def async_create_issue_unsupported_firmware(
"ip_address": entry.data["host"], "ip_address": entry.data["host"],
}, },
) )
def is_rpc_wifi_stations_disabled(
config: dict[str, Any], _status: dict[str, Any], key: str
) -> bool:
"""Return true if rpc all WiFi stations are disabled."""
if config[key]["sta"]["enable"] is True or config[key]["sta1"]["enable"] is True:
return False
return True

View File

@ -159,7 +159,7 @@ MOCK_CONFIG = {
"ui_data": {}, "ui_data": {},
"device": {"name": "Test name"}, "device": {"name": "Test name"},
}, },
"wifi": {"sta": {"enable": True}, "sta1": {"enable": False}}, "wifi": {"sta": {"enable": True}},
} }
MOCK_SHELLY_COAP = { MOCK_SHELLY_COAP = {

View File

@ -27,7 +27,6 @@ from homeassistant.helpers.entity_registry import async_get
from homeassistant.setup import async_setup_component from homeassistant.setup import async_setup_component
from . import ( from . import (
get_entity_state,
init_integration, init_integration,
mock_polling_rpc_update, mock_polling_rpc_update,
mock_rest_update, mock_rest_update,
@ -300,32 +299,6 @@ async def test_rpc_sensor(hass: HomeAssistant, mock_rpc_device, monkeypatch) ->
assert hass.states.get(entity_id).state == STATE_UNKNOWN assert hass.states.get(entity_id).state == STATE_UNKNOWN
async def test_rpc_rssi_sensor_removal(
hass: HomeAssistant,
mock_rpc_device: Mock,
monkeypatch: pytest.MonkeyPatch,
entity_registry_enabled_by_default: None,
) -> None:
"""Test RPC RSSI sensor removal if no WiFi stations enabled."""
entity_id = f"{SENSOR_DOMAIN}.test_name_rssi"
entry = await init_integration(hass, 2)
# WiFi1 enabled, do not remove sensor
assert get_entity_state(hass, entity_id) == "-63"
# WiFi1 & WiFi2 disabled - remove sensor
monkeypatch.setitem(mock_rpc_device.config["wifi"]["sta"], "enable", False)
await hass.config_entries.async_reload(entry.entry_id)
await hass.async_block_till_done()
assert hass.states.get(entity_id) is None
# WiFi2 enabled, do not remove sensor
monkeypatch.setitem(mock_rpc_device.config["wifi"]["sta1"], "enable", True)
await hass.config_entries.async_reload(entry.entry_id)
await hass.async_block_till_done()
assert get_entity_state(hass, entity_id) == "-63"
async def test_rpc_illuminance_sensor( async def test_rpc_illuminance_sensor(
hass: HomeAssistant, mock_rpc_device, monkeypatch hass: HomeAssistant, mock_rpc_device, monkeypatch
) -> None: ) -> None: