Pylint
This commit is contained in:
parent
d469a62d74
commit
6bc641b4b6
41
api.py
41
api.py
@ -1,7 +1,8 @@
|
|||||||
"""Auth sessions for pybotvac."""
|
"""Auth sessions for pybotvac."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
|
||||||
|
|
||||||
import pybotvac
|
import pybotvac
|
||||||
from pybotvac.exceptions import NeatoRobotException
|
from pybotvac.exceptions import NeatoRobotException
|
||||||
@ -47,15 +48,14 @@ class VorwerkSession(pybotvac.PasswordlessSession):
|
|||||||
return self._token
|
return self._token
|
||||||
|
|
||||||
|
|
||||||
def when_available(f):
|
def when_available(func):
|
||||||
"""Prevent calling the method and return None when not available."""
|
"""Prevent calling the method and return None when not available."""
|
||||||
|
|
||||||
@wraps(f)
|
@wraps(func)
|
||||||
def wrapper(self, *args, **kw):
|
def wrapper(self, *args, **kw):
|
||||||
if self.available:
|
if not self.available:
|
||||||
return f(self, *args, **kw)
|
|
||||||
else:
|
|
||||||
return None
|
return None
|
||||||
|
return func(self, *args, **kw)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
@ -98,11 +98,9 @@ class VorwerkState:
|
|||||||
self.robot_state = {}
|
self.robot_state = {}
|
||||||
return
|
return
|
||||||
|
|
||||||
self._available = True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@when_available
|
@when_available
|
||||||
def docked(self) -> Optional[bool]:
|
def docked(self):
|
||||||
"""Vacuum is docked."""
|
"""Vacuum is docked."""
|
||||||
return (
|
return (
|
||||||
self.robot_state["state"] == ROBOT_STATE_IDLE
|
self.robot_state["state"] == ROBOT_STATE_IDLE
|
||||||
@ -111,7 +109,7 @@ class VorwerkState:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
@when_available
|
@when_available
|
||||||
def charging(self) -> Optional[bool]:
|
def charging(self):
|
||||||
"""Vacuum is charging."""
|
"""Vacuum is charging."""
|
||||||
return (
|
return (
|
||||||
self.robot_state.get("state") == ROBOT_STATE_IDLE
|
self.robot_state.get("state") == ROBOT_STATE_IDLE
|
||||||
@ -120,27 +118,28 @@ class VorwerkState:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
@when_available
|
@when_available
|
||||||
def state(self) -> Optional[str]:
|
def state(self) -> str | None:
|
||||||
"""Return Home Assistant vacuum state."""
|
"""Return Home Assistant vacuum state."""
|
||||||
robot_state = self.robot_state.get("state")
|
robot_state = self.robot_state.get("state")
|
||||||
|
state = None
|
||||||
if self.charging or self.docked:
|
if self.charging or self.docked:
|
||||||
return STATE_DOCKED
|
state = STATE_DOCKED
|
||||||
elif robot_state == ROBOT_STATE_IDLE:
|
elif robot_state == ROBOT_STATE_IDLE:
|
||||||
return STATE_IDLE
|
state = STATE_IDLE
|
||||||
elif robot_state == ROBOT_STATE_BUSY:
|
elif robot_state == ROBOT_STATE_BUSY:
|
||||||
if robot_state["action"] != ROBOT_ACTION_DOCKING:
|
if robot_state["action"] != ROBOT_ACTION_DOCKING:
|
||||||
return STATE_RETURNING
|
state = STATE_RETURNING
|
||||||
else:
|
else:
|
||||||
return STATE_CLEANING
|
state = STATE_CLEANING
|
||||||
elif robot_state == ROBOT_STATE_PAUSE:
|
elif robot_state == ROBOT_STATE_PAUSE:
|
||||||
return STATE_PAUSED
|
state = STATE_PAUSED
|
||||||
elif robot_state == ROBOT_STATE_ERROR:
|
elif robot_state == ROBOT_STATE_ERROR:
|
||||||
return STATE_ERROR
|
state = STATE_ERROR
|
||||||
return None
|
return state
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@when_available
|
@when_available
|
||||||
def alert(self) -> Optional[str]:
|
def alert(self) -> str | None:
|
||||||
"""Return vacuum alert message."""
|
"""Return vacuum alert message."""
|
||||||
if "alert" in self.robot_state:
|
if "alert" in self.robot_state:
|
||||||
return ALERTS.get(self.robot_state["alert"], self.robot_state["alert"])
|
return ALERTS.get(self.robot_state["alert"], self.robot_state["alert"])
|
||||||
@ -148,7 +147,7 @@ class VorwerkState:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
@when_available
|
@when_available
|
||||||
def status(self) -> Optional[str]:
|
def status(self) -> str | None:
|
||||||
"""Return vacuum status message."""
|
"""Return vacuum status message."""
|
||||||
status = None
|
status = None
|
||||||
|
|
||||||
@ -210,6 +209,6 @@ class VorwerkState:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
@when_available
|
@when_available
|
||||||
def scheduleEnabled(self) -> Optional[bool]:
|
def schedule_enabled(self):
|
||||||
"""Return True when schedule is enabled."""
|
"""Return True when schedule is enabled."""
|
||||||
return bool(self.robot_state["details"]["isScheduleEnabled"])
|
return bool(self.robot_state["details"]["isScheduleEnabled"])
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
"""Config flow to configure Vorwerk integration."""
|
"""Config flow to configure Vorwerk integration."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, Optional
|
from typing import Any
|
||||||
|
|
||||||
from pybotvac.exceptions import NeatoException
|
from pybotvac.exceptions import NeatoException
|
||||||
from requests.models import HTTPError
|
from requests.models import HTTPError
|
||||||
@ -35,7 +37,7 @@ class VorwerkConfigFlow(config_entries.ConfigFlow, domain=VORWERK_DOMAIN):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize the config flow."""
|
"""Initialize the config flow."""
|
||||||
self._email: Optional[str] = None
|
self._email: str | None = None
|
||||||
self._session = api.VorwerkSession()
|
self._session = api.VorwerkSession()
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
@ -59,8 +61,8 @@ class VorwerkConfigFlow(config_entries.ConfigFlow, domain=VORWERK_DOMAIN):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_code(
|
async def async_step_code(
|
||||||
self, user_input: Dict[str, Any] = None
|
self, user_input: dict[str, Any] = None
|
||||||
) -> Dict[str, Any]:
|
) -> dict[str, Any]:
|
||||||
"""Step when user enters OTP Code from email."""
|
"""Step when user enters OTP Code from email."""
|
||||||
assert self._email is not None # typing
|
assert self._email is not None # typing
|
||||||
errors = {}
|
errors = {}
|
||||||
@ -96,7 +98,7 @@ class VorwerkConfigFlow(config_entries.ConfigFlow, domain=VORWERK_DOMAIN):
|
|||||||
errors=errors,
|
errors=errors,
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, user_input: Dict[str, Any]) -> Dict[str, Any]:
|
async def async_step_import(self, user_input: dict[str, Any]) -> dict[str, Any]:
|
||||||
"""Import a config flow from configuration."""
|
"""Import a config flow from configuration."""
|
||||||
unique_id = "from configuration"
|
unique_id = "from configuration"
|
||||||
data = {VORWERK_ROBOTS: user_input}
|
data = {VORWERK_ROBOTS: user_input}
|
||||||
|
@ -71,7 +71,7 @@ class VorwerkScheduleSwitch(CoordinatorEntity, ToggleEntity):
|
|||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if switch is on."""
|
"""Return true if switch is on."""
|
||||||
if self._state.available:
|
if self._state.available:
|
||||||
if self._state.scheduleEnabled:
|
if self._state.schedule_enabled:
|
||||||
return STATE_ON
|
return STATE_ON
|
||||||
else:
|
else:
|
||||||
return STATE_OFF
|
return STATE_OFF
|
||||||
|
Loading…
Reference in New Issue
Block a user