From 30920c3da7a714c5fef85fba4bd84191a9e5f44d Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Wed, 12 Oct 2022 15:52:09 +0200 Subject: [PATCH] Code quality improvements for Fully Kiosk (#80168) --- .../components/fully_kiosk/manifest.json | 1 - .../components/fully_kiosk/strings.json | 1 - .../components/fully_kiosk/switch.py | 6 +-- .../fully_kiosk/translations/en.json | 1 - tests/components/fully_kiosk/test_button.py | 42 +++++++++++++------ 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/fully_kiosk/manifest.json b/homeassistant/components/fully_kiosk/manifest.json index 8918ce28062..5601cb074f0 100644 --- a/homeassistant/components/fully_kiosk/manifest.json +++ b/homeassistant/components/fully_kiosk/manifest.json @@ -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 }] diff --git a/homeassistant/components/fully_kiosk/strings.json b/homeassistant/components/fully_kiosk/strings.json index 05b9e067962..873ebc661fb 100644 --- a/homeassistant/components/fully_kiosk/strings.json +++ b/homeassistant/components/fully_kiosk/strings.json @@ -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": { diff --git a/homeassistant/components/fully_kiosk/switch.py b/homeassistant/components/fully_kiosk/switch.py index 581700c87d6..28407a66da1 100644 --- a/homeassistant/components/fully_kiosk/switch.py +++ b/homeassistant/components/fully_kiosk/switch.py @@ -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.""" diff --git a/homeassistant/components/fully_kiosk/translations/en.json b/homeassistant/components/fully_kiosk/translations/en.json index 338c50514fb..24823d68a60 100644 --- a/homeassistant/components/fully_kiosk/translations/en.json +++ b/homeassistant/components/fully_kiosk/translations/en.json @@ -5,7 +5,6 @@ }, "error": { "cannot_connect": "Failed to connect", - "invalid_auth": "Invalid authentication", "unknown": "Unexpected error" }, "step": { diff --git a/tests/components/fully_kiosk/test_button.py b/tests/components/fully_kiosk/test_button.py index 8616d7107f7..1c839e57dfd 100644 --- a/tests/components/fully_kiosk/test_button.py +++ b/tests/components/fully_kiosk/test_button.py @@ -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 - )