Skip to content

Commit 8c2ee0b

Browse files
committed
CI linter fixes
1 parent 7937b2c commit 8c2ee0b

File tree

9 files changed

+43
-38
lines changed

9 files changed

+43
-38
lines changed

custom_components/switch_cfw/config_flow.py

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
import aiohttp
99
import voluptuous as vol
1010

11-
from homeassistant import config_entries
1211
from homeassistant.components import network
12+
from homeassistant.config_entries import (
13+
ConfigEntry,
14+
ConfigFlow as ConfigFlowBase,
15+
ConfigFlowResult,
16+
OptionsFlow,
17+
ZeroconfServiceInfo,
18+
)
1319
from homeassistant.const import CONF_HOST, CONF_NAME
1420
from homeassistant.core import callback
1521
from homeassistant.data_entry_flow import FlowResult
@@ -28,7 +34,7 @@
2834
)
2935

3036

31-
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): # type: ignore[call-arg]
37+
class ConfigFlow(ConfigFlowBase, domain=DOMAIN): # type: ignore[call-arg]
3238
"""Handle a config flow for Nintendo Switch CFW."""
3339

3440
VERSION = 1
@@ -40,13 +46,13 @@ def __init__(self) -> None:
4046

4147
async def async_step_user(
4248
self, user_input: dict[str, Any] | None = None
43-
) -> FlowResult:
49+
) -> ConfigFlowResult:
4450
"""Handle the initial step."""
4551

4652
if user_input is not None:
4753
if user_input.get("flow_type") == "manual":
4854
return await self.async_step_manual_entry()
49-
return await self.async_step_discovery()
55+
return await self.async_step_select_device()
5056

5157
return self.async_show_form(
5258
step_id="user",
@@ -59,9 +65,13 @@ async def async_step_user(
5965
),
6066
)
6167

62-
async def async_step_discovery(
68+
async def async_step_discovery(self, discovery_info: dict[str, Any]) -> ConfigFlowResult:
69+
"""Handle discovery."""
70+
return await self.async_step_select_device()
71+
72+
async def async_step_select_device(
6373
self, user_input: dict[str, Any] | None = None
64-
) -> FlowResult:
74+
) -> ConfigFlowResult:
6575
"""Scan for Nintendo Switch consoles in the background."""
6676
if user_input is not None:
6777
# We already have discovered devices, let the user select one
@@ -194,7 +204,7 @@ async def async_step_manual_entry(
194204
self._host,
195205
err.status,
196206
)
197-
except aiohttp.ClientError, asyncio.TimeoutError:
207+
except (aiohttp.ClientError, asyncio.TimeoutError):
198208
errors["base"] = "cannot_connect"
199209
LOGGER.error("Manual connection to %s timed out or failed", self._host)
200210
except Exception as err:
@@ -221,8 +231,8 @@ async def async_step_manual_entry(
221231
)
222232

223233
async def async_step_zeroconf(
224-
self, discovery_info: config_entries.ZeroconfServiceInfo
225-
) -> FlowResult:
234+
self, discovery_info: ZeroconfServiceInfo
235+
) -> ConfigFlowResult:
226236
"""Handle zeroconf discovery."""
227237
self._host = discovery_info.host
228238
self._name = "Nintendo Switch"
@@ -282,7 +292,7 @@ async def async_step_discovery_confirm(
282292
self._host,
283293
err.status,
284294
)
285-
except aiohttp.ClientError, asyncio.TimeoutError:
295+
except (aiohttp.ClientError, asyncio.TimeoutError):
286296
errors["base"] = "cannot_connect"
287297
LOGGER.error(
288298
"Discovery confirmation for %s timed out or failed", self._host
@@ -304,22 +314,18 @@ async def async_step_discovery_confirm(
304314
@staticmethod
305315
@callback
306316
def async_get_options_flow(
307-
config_entry: config_entries.ConfigEntry,
308-
) -> config_entries.OptionsFlow:
317+
config_entry: ConfigEntry,
318+
) -> OptionsFlow:
309319
"""Create the options flow."""
310320
return OptionsFlowHandler(config_entry)
311321

312322

313-
class OptionsFlowHandler(config_entries.OptionsFlow):
323+
class OptionsFlowHandler(OptionsFlow):
314324
"""Handle an options flow for Nintendo Switch CFW."""
315325

316-
def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
317-
"""Initialize options flow."""
318-
self.config_entry = config_entry
319-
320326
async def async_step_init(
321327
self, user_input: dict[str, Any] | None = None
322-
) -> FlowResult:
328+
) -> ConfigFlowResult:
323329
"""Manage the options."""
324330
if user_input is not None:
325331
return self.async_create_entry(title="", data=user_input)

custom_components/switch_cfw/remote.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ class SwitchRemote(SwitchEntity, RemoteEntity):
2929
"""Representation of a Nintendo Switch remote."""
3030

3131
_attr_translation_key = "remote"
32-
_attr_supported_features = (
33-
RemoteEntityFeature.RECALL_SCENE | RemoteEntityFeature.ACTIVITY
34-
)
32+
_attr_supported_features = RemoteEntityFeature.ACTIVITY
3533

3634
def __init__(self, coordinator: SwitchDataUpdateCoordinator) -> None:
3735
"""Initialize the remote."""

custom_components/switch_cfw/select.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from typing import cast
1313
from .const import DOMAIN, LOGGER
1414
from .coordinator import SwitchDataUpdateCoordinator
15+
from .entity import SwitchEntity
1516

1617

1718
async def async_setup_entry(
@@ -24,7 +25,7 @@ async def async_setup_entry(
2425
async_add_entities([SwitchGameSelect(coordinator)])
2526

2627

27-
class SwitchGameSelect(CoordinatorEntity[SwitchDataUpdateCoordinator], SelectEntity):
28+
class SwitchGameSelect(SwitchEntity, SelectEntity):
2829
"""Representation of an installed game select entity."""
2930

3031
_attr_translation_key = "game_list"
@@ -33,8 +34,7 @@ class SwitchGameSelect(CoordinatorEntity[SwitchDataUpdateCoordinator], SelectEnt
3334
def __init__(self, coordinator: SwitchDataUpdateCoordinator) -> None:
3435
"""Initialize the select entity."""
3536
super().__init__(coordinator)
36-
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_games"
37-
self._attr_device_info = coordinator.device_info
37+
self._attr_unique_id = f"{coordinator.entry.entry_id}_games"
3838
self._titles: dict[str, str] = {} # Name -> ID
3939

4040
@property

custom_components/switch_cfw/sensor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
1818
)
1919
from homeassistant.core import HomeAssistant
20+
from homeassistant.helpers.entity import EntityCategory
2021
from homeassistant.helpers.entity_platform import AddEntitiesCallback
2122

2223
from .const import (
@@ -230,7 +231,7 @@ class LogSensor(SwitchEntity, SensorEntity):
230231

231232
_attr_translation_key = "sysmodule_logs"
232233
_attr_icon = "mdi:text-long"
233-
_attr_entity_category = "diagnostic"
234+
_attr_entity_category = EntityCategory.DIAGNOSTIC
234235

235236
@property
236237
def native_value(self) -> int | None:

custom_components/switch_cfw/update.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from .const import DOMAIN, LOGGER, ATTR_APP_VERSION
1818
from .coordinator import SwitchDataUpdateCoordinator
19+
from .entity import SwitchEntity
1920

2021

2122
async def async_setup_entry(
@@ -33,7 +34,7 @@ async def async_setup_entry(
3334
async_add_entities(entities)
3435

3536

36-
class SwitchUpdateEntity(CoordinatorEntity[SwitchDataUpdateCoordinator], UpdateEntity):
37+
class SwitchUpdateEntity(SwitchEntity, UpdateEntity):
3738
"""Base class for Switch update entities."""
3839

3940
_attr_has_entity_name = True
@@ -43,7 +44,6 @@ class SwitchUpdateEntity(CoordinatorEntity[SwitchDataUpdateCoordinator], UpdateE
4344
def __init__(self, coordinator: SwitchDataUpdateCoordinator) -> None:
4445
"""Initialize the update entity."""
4546
super().__init__(coordinator)
46-
self._attr_device_info = coordinator.device_info
4747

4848

4949
class SwitchSystemUpdate(SwitchUpdateEntity):
@@ -54,7 +54,7 @@ class SwitchSystemUpdate(SwitchUpdateEntity):
5454
def __init__(self, coordinator: SwitchDataUpdateCoordinator) -> None:
5555
"""Initialize the system update entity."""
5656
super().__init__(coordinator)
57-
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_firmware"
57+
self._attr_unique_id = f"{coordinator.entry.entry_id}_firmware"
5858

5959
@property
6060
def installed_version(self) -> str | None:
@@ -82,7 +82,7 @@ class SwitchAppUpdate(SwitchUpdateEntity):
8282
def __init__(self, coordinator: SwitchDataUpdateCoordinator) -> None:
8383
"""Initialize the app update entity."""
8484
super().__init__(coordinator)
85-
self._attr_unique_id = f"{coordinator.entry_id}_app_update"
85+
self._attr_unique_id = f"{coordinator.entry.entry_id}_app_update"
8686
# For the app update, we'll use our own repo versioning
8787
self._repo = "FaserF/ha-NintendoSwitchCFW"
8888

tests/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ async def test_api_get_info():
1212

1313
mock_response = MagicMock()
1414
mock_response.status = 200
15-
mock_response.json = MagicMock(return_value={"firmware": "17.0.1"})
15+
mock_response.json = MagicMock(return_value={"firmware_version": "17.0.1"})
1616

1717
with patch(
1818
"aiohttp.ClientSession.get",
1919
return_value=MagicMock(__aenter__=MagicMock(return_value=mock_response)),
2020
):
2121
info = await api.get_info()
22-
assert info["firmware"] == "17.0.1"
22+
assert info["firmware_version"] == "17.0.1"
2323

2424

2525
@pytest.mark.asyncio
2626
async def test_api_reboot():
2727
"""Test reboot method."""
28-
api = SwitchAPI("1.2.3.4")
28+
api = SwitchAPI("1.2.3.4", "test_token")
2929

3030
mock_response = MagicMock()
3131
mock_response.status = 200

tests/test_binary_sensor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from custom_components.switch_cfw.binary_sensor import (
66
ChargingBinarySensor,
77
DockedBinarySensor,
8-
SleepModeBinarySensor,
8+
SleepBinarySensor,
99
)
1010

1111

@@ -30,7 +30,7 @@ async def test_binary_sensor_states(mock_hass, mock_config_entry):
3030
assert sensor.is_on is True
3131

3232
# Test Sleep Mode Binary Sensor
33-
sensor = SleepModeBinarySensor(coordinator)
33+
sensor = SleepBinarySensor(coordinator)
3434
assert sensor.is_on is False
3535

3636
# Test Sleep Mode On

tests/test_button.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from unittest.mock import MagicMock, AsyncMock
5-
from custom_components.switch_cfw.button import SwitchButton
5+
from custom_components.switch_cfw.button import RebootButton, ShutdownButton
66

77

88
@pytest.mark.asyncio
@@ -12,11 +12,11 @@ async def test_button_press(mock_hass, mock_config_entry):
1212
coordinator.api = AsyncMock()
1313

1414
# Test Reboot Button
15-
button = SwitchButton(coordinator, mock_config_entry, "reboot")
15+
button = RebootButton(coordinator)
1616
await button.async_press()
1717
coordinator.api.reboot.assert_called_once()
1818

1919
# Test Shutdown Button
20-
button = SwitchButton(coordinator, mock_config_entry, "shutdown")
20+
button = ShutdownButton(coordinator)
2121
await button.async_press()
2222
coordinator.api.shutdown.assert_called_once()

tests/test_coordinator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pytest
44
from datetime import timedelta
55
from homeassistant.helpers.update_coordinator import UpdateFailed
6-
from custom_components.switch_cfw.coordinator import SwitchCoordinator
6+
from custom_components.switch_cfw.coordinator import SwitchDataUpdateCoordinator
77

88

99
@pytest.mark.asyncio

0 commit comments

Comments
 (0)