Code quality improvements for Fully Kiosk (#80168)

This commit is contained in:
Franck Nijhof 2022-10-12 15:52:09 +02:00 committed by GitHub
parent 4a1c40f09b
commit 30920c3da7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 18 deletions

View File

@ -4,7 +4,6 @@
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/fullykiosk",
"requirements": ["python-fullykiosk==0.0.11"],
"dependencies": [],
"codeowners": ["@cgarwood"],
"iot_class": "local_polling",
"dhcp": [{ "registered_devices": true }]

View File

@ -10,7 +10,6 @@
},
"error": {
"cannot_connect": "[%key:common::config_flow::error::cannot_connect%]",
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {

View File

@ -109,9 +109,9 @@ class FullySwitchEntity(FullyKioskEntity, SwitchEntity):
@property
def is_on(self) -> bool | None:
"""Return true if the entity is on."""
if self.entity_description.is_on_fn(self.coordinator.data) is not None:
return bool(self.entity_description.is_on_fn(self.coordinator.data))
return None
if (is_on := self.entity_description.is_on_fn(self.coordinator.data)) is None:
return None
return bool(is_on)
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the entity on."""

View File

@ -5,7 +5,6 @@
},
"error": {
"cannot_connect": "Failed to connect",
"invalid_auth": "Invalid authentication",
"unknown": "Unexpected error"
},
"step": {

View File

@ -22,31 +22,56 @@ async def test_buttons(
entry = entity_registry.async_get("button.amazon_fire_restart_browser")
assert entry
assert entry.unique_id == "abcdef-123456-restartApp"
await call_service(hass, "press", "button.amazon_fire_restart_browser")
assert await hass.services.async_call(
button.DOMAIN,
button.SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.amazon_fire_restart_browser"},
blocking=True,
)
assert len(mock_fully_kiosk.restartApp.mock_calls) == 1
entry = entity_registry.async_get("button.amazon_fire_reboot_device")
assert entry
assert entry.unique_id == "abcdef-123456-rebootDevice"
await call_service(hass, "press", "button.amazon_fire_reboot_device")
assert await hass.services.async_call(
button.DOMAIN,
button.SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.amazon_fire_reboot_device"},
blocking=True,
)
assert len(mock_fully_kiosk.rebootDevice.mock_calls) == 1
entry = entity_registry.async_get("button.amazon_fire_bring_to_foreground")
assert entry
assert entry.unique_id == "abcdef-123456-toForeground"
await call_service(hass, "press", "button.amazon_fire_bring_to_foreground")
assert await hass.services.async_call(
button.DOMAIN,
button.SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.amazon_fire_bring_to_foreground"},
blocking=True,
)
assert len(mock_fully_kiosk.toForeground.mock_calls) == 1
entry = entity_registry.async_get("button.amazon_fire_send_to_background")
assert entry
assert entry.unique_id == "abcdef-123456-toBackground"
await call_service(hass, "press", "button.amazon_fire_send_to_background")
assert await hass.services.async_call(
button.DOMAIN,
button.SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.amazon_fire_send_to_background"},
blocking=True,
)
assert len(mock_fully_kiosk.toBackground.mock_calls) == 1
entry = entity_registry.async_get("button.amazon_fire_load_start_url")
assert entry
assert entry.unique_id == "abcdef-123456-loadStartUrl"
await call_service(hass, "press", "button.amazon_fire_load_start_url")
assert await hass.services.async_call(
button.DOMAIN,
button.SERVICE_PRESS,
{ATTR_ENTITY_ID: "button.amazon_fire_load_start_url"},
blocking=True,
)
assert len(mock_fully_kiosk.loadStartUrl.mock_calls) == 1
assert entry.device_id
@ -60,10 +85,3 @@ async def test_buttons(
assert device_entry.model == "KFDOWI"
assert device_entry.name == "Amazon Fire"
assert device_entry.sw_version == "1.42.5"
def call_service(hass, service, entity_id):
"""Call any service on entity."""
return hass.services.async_call(
button.DOMAIN, service, {ATTR_ENTITY_ID: entity_id}, blocking=True
)