Disable Aladdin Connect battery_level by default (#75441)

* Disable battery_level by default

* Removed async_setup_compnent, renamed constant.
This commit is contained in:
mkmer 2022-07-19 21:23:14 -04:00 committed by GitHub
parent d09fff595c
commit 07b4d48e7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 92 additions and 6 deletions

View file

@ -42,6 +42,7 @@ SENSORS: tuple[AccSensorEntityDescription, ...] = (
key="battery_level",
name="Battery level",
device_class=SensorDeviceClass.BATTERY,
entity_registry_enabled_default=False,
native_unit_of_measurement=PERCENTAGE,
state_class=SensorStateClass.MEASUREMENT,
value_fn=AladdinConnectClient.get_battery_status,

View file

@ -9,14 +9,14 @@ from homeassistant.core import HomeAssistant
from tests.common import AsyncMock, MockConfigEntry
YAML_CONFIG = {"username": "test-user", "password": "test-password"}
CONFIG = {"username": "test-user", "password": "test-password"}
async def test_setup_get_doors_errors(hass: HomeAssistant) -> None:
"""Test component setup Get Doors Errors."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data=YAML_CONFIG,
data=CONFIG,
unique_id="test-id",
)
config_entry.add_to_hass(hass)
@ -38,7 +38,7 @@ async def test_setup_login_error(
"""Test component setup Login Errors."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data=YAML_CONFIG,
data=CONFIG,
unique_id="test-id",
)
config_entry.add_to_hass(hass)
@ -57,7 +57,7 @@ async def test_setup_connection_error(
"""Test component setup Login Errors."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data=YAML_CONFIG,
data=CONFIG,
unique_id="test-id",
)
config_entry.add_to_hass(hass)
@ -74,7 +74,7 @@ async def test_setup_component_no_error(hass: HomeAssistant) -> None:
"""Test component setup No Error."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data=YAML_CONFIG,
data=CONFIG,
unique_id="test-id",
)
config_entry.add_to_hass(hass)
@ -116,7 +116,7 @@ async def test_load_and_unload(
"""Test loading and unloading Aladdin Connect entry."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data=YAML_CONFIG,
data=CONFIG,
unique_id="test-id",
)
config_entry.add_to_hass(hass)

View file

@ -0,0 +1,85 @@
"""Test the Aladdin Connect Sensors."""
from datetime import timedelta
from unittest.mock import MagicMock, patch
from homeassistant.components.aladdin_connect.const import DOMAIN
from homeassistant.components.aladdin_connect.cover import SCAN_INTERVAL
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity_registry
from homeassistant.util.dt import utcnow
from tests.common import MockConfigEntry, async_fire_time_changed
CONFIG = {"username": "test-user", "password": "test-password"}
RELOAD_AFTER_UPDATE_DELAY = timedelta(seconds=31)
async def test_sensors(
hass: HomeAssistant,
mock_aladdinconnect_api: MagicMock,
) -> None:
"""Test Sensors for AladdinConnect."""
config_entry = MockConfigEntry(
domain=DOMAIN,
data=CONFIG,
unique_id="test-id",
)
config_entry.add_to_hass(hass)
await hass.async_block_till_done()
with patch(
"homeassistant.components.aladdin_connect.AladdinConnectClient",
return_value=mock_aladdinconnect_api,
):
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
registry = entity_registry.async_get(hass)
entry = registry.async_get("sensor.home_battery_level")
assert entry
assert entry.disabled
assert entry.disabled_by is entity_registry.RegistryEntryDisabler.INTEGRATION
update_entry = registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)
await hass.async_block_till_done()
assert update_entry != entry
assert update_entry.disabled is False
state = hass.states.get("sensor.home_battery_level")
assert state is None
async_fire_time_changed(
hass,
utcnow() + SCAN_INTERVAL,
)
await hass.async_block_till_done()
state = hass.states.get("sensor.home_battery_level")
assert state
entry = registry.async_get("sensor.home_wi_fi_rssi")
await hass.async_block_till_done()
assert entry
assert entry.disabled
assert entry.disabled_by is entity_registry.RegistryEntryDisabler.INTEGRATION
update_entry = registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)
await hass.async_block_till_done()
assert update_entry != entry
assert update_entry.disabled is False
state = hass.states.get("sensor.home_wi_fi_rssi")
assert state is None
update_entry = registry.async_update_entity(
entry.entity_id, **{"disabled_by": None}
)
await hass.async_block_till_done()
async_fire_time_changed(
hass,
utcnow() + SCAN_INTERVAL,
)
await hass.async_block_till_done()
state = hass.states.get("sensor.home_wi_fi_rssi")
assert state