Skip to content

Commit 509e3c8

Browse files
authored
Replace deprecated class properties (#694)
1 parent 5937a2d commit 509e3c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+195
-178
lines changed

deebot_client/command.py

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ApiTimeoutError,
1313
DeebotError,
1414
)
15+
from deebot_client.util import verify_required_class_variables_exists
1516

1617
from .const import PATH_API_IOT_DEVMANAGER, REQUEST_HEADERS, DataType
1718
from .logging_filter import get_logger
@@ -64,24 +65,18 @@ class Command(ABC):
6465
"""Abstract command object."""
6566

6667
_targets_bot: bool = True
68+
NAME: str
69+
DATA_TYPE: DataType
70+
71+
def __init_subclass__(cls) -> None:
72+
verify_required_class_variables_exists(cls, ("NAME", "DATA_TYPE"))
73+
return super().__init_subclass__()
6774

6875
def __init__(self, args: dict[str, Any] | list[Any] | None = None) -> None:
6976
if args is None:
7077
args = {}
7178
self._args = args
7279

73-
@property # type: ignore[misc]
74-
@classmethod
75-
@abstractmethod
76-
def name(cls) -> str:
77-
"""Command name."""
78-
79-
@property # type: ignore[misc]
80-
@classmethod
81-
@abstractmethod
82-
def data_type(cls) -> DataType:
83-
"""Data type."""
84-
8580
@abstractmethod
8681
def _get_payload(self) -> dict[str, Any] | list[Any] | str:
8782
"""Get the payload for the rest call."""
@@ -115,7 +110,7 @@ async def execute(
115110
except Exception: # pylint: disable=broad-except
116111
_LOGGER.warning(
117112
"Could not execute command %s",
118-
self.name,
113+
self.NAME,
119114
exc_info=True,
120115
)
121116
return DeviceCommandResult(device_reached=False)
@@ -132,14 +127,14 @@ async def _execute(
132127
except ApiTimeoutError:
133128
_LOGGER.warning(
134129
"Could not execute command %s: Timeout reached",
135-
self.name,
130+
self.NAME,
136131
)
137132
return CommandResult(HandlingState.ERROR), {}
138133

139134
result = self.__handle_response(event_bus, response)
140135
if result.state == HandlingState.ANALYSE:
141136
_LOGGER.debug(
142-
"ANALYSE: Could not handle command: %s with %s", self.name, response
137+
"ANALYSE: Could not handle command: %s with %s", self.NAME, response
143138
)
144139
return (
145140
CommandResult(
@@ -150,16 +145,16 @@ async def _execute(
150145
response,
151146
)
152147
if result.state == HandlingState.ERROR:
153-
_LOGGER.warning("Could not parse %s: %s", self.name, response)
148+
_LOGGER.warning("Could not parse %s: %s", self.NAME, response)
154149
return result, response
155150

156151
async def _execute_api_request(
157152
self, authenticator: Authenticator, device_info: ApiDeviceInfo
158153
) -> dict[str, Any]:
159154
payload = {
160-
"cmdName": self.name,
155+
"cmdName": self.NAME,
161156
"payload": self._get_payload(),
162-
"payloadType": self.data_type.value,
157+
"payloadType": self.DATA_TYPE.value,
163158
"td": "q",
164159
"toId": device_info["did"],
165160
"toRes": device_info["resource"],
@@ -195,7 +190,7 @@ def __handle_response(
195190
result = self._handle_response(event_bus, response)
196191
if result.state == HandlingState.ANALYSE:
197192
_LOGGER.debug(
198-
"ANALYSE: Could not handle command: %s with %s", self.name, response
193+
"ANALYSE: Could not handle command: %s with %s", self.NAME, response
199194
)
200195
return CommandResult(
201196
HandlingState.ANALYSE_LOGGED,
@@ -206,7 +201,7 @@ def __handle_response(
206201
except Exception: # pylint: disable=broad-except
207202
_LOGGER.warning(
208203
"Could not parse response for %s: %s",
209-
self.name,
204+
self.NAME,
210205
response,
211206
exc_info=True,
212207
)
@@ -223,12 +218,12 @@ def _handle_response(
223218

224219
def __eq__(self, obj: object) -> bool:
225220
if isinstance(obj, Command):
226-
return self.name == obj.name and self._args == obj._args
221+
return self.NAME == obj.NAME and self._args == obj._args
227222

228223
return False
229224

230225
def __hash__(self) -> int:
231-
return hash(self.name) + hash(self._args)
226+
return hash(self.NAME) + hash(self._args)
232227

233228

234229
class CommandWithMessageHandling(Command, Message, ABC):
@@ -253,24 +248,24 @@ def _handle_response(
253248
case 4200:
254249
# bot offline
255250
_LOGGER.info(
256-
'Device is offline. Could not execute command "%s"', self.name
251+
'Device is offline. Could not execute command "%s"', self.NAME
257252
)
258253
event_bus.notify(AvailabilityEvent(available=False))
259254
return CommandResult(HandlingState.FAILED)
260255
case 500:
261256
if self._is_available_check:
262257
_LOGGER.info(
263258
'No response received for command "%s" during availability-check.',
264-
self.name,
259+
self.NAME,
265260
)
266261
else:
267262
_LOGGER.warning(
268263
'No response received for command "%s". This can happen if the device has network issues or does not support the command',
269-
self.name,
264+
self.NAME,
270265
)
271266
return CommandResult(HandlingState.FAILED)
272267

273-
_LOGGER.warning('Command "%s" was not successfully.', self.name)
268+
_LOGGER.warning('Command "%s" was not successfully.', self.NAME)
274269
return CommandResult(HandlingState.ANALYSE)
275270

276271

deebot_client/commands/json/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@
230230
]
231231
# fmt: on
232232

233-
COMMANDS: dict[str, type[Command]] = {
234-
cmd.name: cmd # type: ignore[misc]
235-
for cmd in _COMMANDS
236-
}
233+
COMMANDS: dict[str, type[Command]] = {cmd.NAME: cmd for cmd in _COMMANDS}
237234

238235
COMMANDS_WITH_MQTT_P2P_HANDLING: dict[str, type[CommandMqttP2P]] = {
239236
cmd_name: cmd

deebot_client/commands/json/advanced_mode.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
class GetAdvancedMode(GetEnableCommand):
1111
"""Get advanced mode command."""
1212

13-
name = "getAdvancedMode"
14-
event_type = AdvancedModeEvent
13+
NAME = "getAdvancedMode"
14+
EVENT_TYPE = AdvancedModeEvent
1515

1616

1717
class SetAdvancedMode(SetEnableCommand):
1818
"""Set advanced mode command."""
1919

20-
name = "setAdvancedMode"
20+
NAME = "setAdvancedMode"
2121
get_command = GetAdvancedMode

deebot_client/commands/json/battery.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class GetBattery(OnBattery, JsonCommandWithMessageHandling):
1111
"""Get battery command."""
1212

13-
name = "getBattery"
13+
NAME = "getBattery"
1414

1515
def __init__(self, *, is_available_check: bool = False) -> None:
1616
super().__init__()

deebot_client/commands/json/border_switch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
class GetBorderSwitch(GetEnableCommand):
1111
"""Get border switch command."""
1212

13-
name = "getBorderSwitch"
14-
event_type = BorderSwitchEvent
13+
NAME = "getBorderSwitch"
14+
EVENT_TYPE = BorderSwitchEvent
1515

1616

1717
class SetBorderSwitch(SetEnableCommand):
1818
"""Set border switch command."""
1919

20-
name = "setBorderSwitch"
20+
NAME = "setBorderSwitch"
2121
get_command = GetBorderSwitch

deebot_client/commands/json/carpet.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
class GetCarpetAutoFanBoost(GetEnableCommand):
1111
"""Get carpet auto fan boost command."""
1212

13-
name = "getCarpertPressure"
14-
event_type = CarpetAutoFanBoostEvent
13+
NAME = "getCarpertPressure"
14+
EVENT_TYPE = CarpetAutoFanBoostEvent
1515

1616

1717
class SetCarpetAutoFanBoost(SetEnableCommand):
1818
"""Set carpet auto fan boost command."""
1919

20-
name = "setCarpertPressure"
20+
NAME = "setCarpertPressure"
2121
get_command = GetCarpetAutoFanBoost

deebot_client/commands/json/charge.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
class Charge(ExecuteCommand):
2222
"""Charge command."""
2323

24-
name = "charge"
24+
NAME = "charge"
2525

2626
def __init__(self) -> None:
2727
super().__init__({"act": "go"})

deebot_client/commands/json/charge_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class GetChargeState(JsonCommandWithMessageHandling, MessageBodyDataDict):
1919
"""Get charge state command."""
2020

21-
name = "getChargeState"
21+
NAME = "getChargeState"
2222

2323
@classmethod
2424
def _handle_body_data_dict(

deebot_client/commands/json/child_lock.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
class GetChildLock(GetEnableCommand):
1111
"""Get child lock command."""
1212

13-
name = "getChildLock"
14-
event_type = ChildLockEvent
13+
NAME = "getChildLock"
14+
EVENT_TYPE = ChildLockEvent
1515
_field_name = "on"
1616

1717

1818
class SetChildLock(SetEnableCommand):
1919
"""Set child lock command."""
2020

21-
name = "setChildLock"
21+
NAME = "setChildLock"
2222
get_command = GetChildLock
2323
_field_name = "on"

deebot_client/commands/json/clean.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
class Clean(ExecuteCommand):
2323
"""Clean command."""
2424

25-
name = "clean"
25+
NAME = "clean"
2626

2727
def __init__(self, action: CleanAction) -> None:
2828
super().__init__(self._get_args(action))
@@ -77,7 +77,7 @@ def _get_args(self, action: CleanAction) -> dict[str, Any]:
7777
class CleanV2(Clean):
7878
"""Clean V2 command."""
7979

80-
name = "clean_V2"
80+
NAME = "clean_V2"
8181

8282
def _get_args(self, action: CleanAction) -> dict[str, Any]:
8383
content: dict[str, str] = {}
@@ -107,7 +107,7 @@ def _get_args(self, action: CleanAction) -> dict[str, Any]:
107107
class GetCleanInfo(JsonCommandWithMessageHandling, MessageBodyDataDict):
108108
"""Get clean info command."""
109109

110-
name = "getCleanInfo"
110+
NAME = "getCleanInfo"
111111

112112
@classmethod
113113
def _handle_body_data_dict(
@@ -158,4 +158,4 @@ def _handle_body_data_dict(
158158
class GetCleanInfoV2(GetCleanInfo):
159159
"""Get clean info v2 command."""
160160

161-
name = "getCleanInfo_V2"
161+
NAME = "getCleanInfo_V2"

deebot_client/commands/json/clean_count.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class GetCleanCount(JsonGetCommand):
1919
"""Get clean count command."""
2020

21-
name = "getCleanCount"
21+
NAME = "getCleanCount"
2222

2323
@classmethod
2424
def _handle_body_data_dict(
@@ -35,7 +35,7 @@ def _handle_body_data_dict(
3535
class SetCleanCount(JsonSetCommand):
3636
"""Set clean count command."""
3737

38-
name = "setCleanCount"
38+
NAME = "setCleanCount"
3939
get_command = GetCleanCount
4040
_mqtt_params = MappingProxyType({"count": InitParam(int)})
4141

deebot_client/commands/json/clean_logs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class GetCleanLogs(JsonCommand):
2323
"""Get clean logs command."""
2424

2525
_targets_bot: bool = False
26-
name = "GetCleanLogs"
26+
NAME = "GetCleanLogs"
2727

2828
def __init__(self, count: int = 0) -> None:
2929
super().__init__({"count": count})
@@ -32,7 +32,7 @@ async def _execute_api_request(
3232
self, authenticator: Authenticator, device_info: ApiDeviceInfo
3333
) -> dict[str, Any]:
3434
json = {
35-
"td": self.name,
35+
"td": self.NAME,
3636
"did": device_info["did"],
3737
"resource": device_info["resource"],
3838
}

deebot_client/commands/json/clean_preference.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
class GetCleanPreference(GetEnableCommand):
1111
"""Get clean preference command."""
1212

13-
name = "getCleanPreference"
14-
event_type = CleanPreferenceEvent
13+
NAME = "getCleanPreference"
14+
EVENT_TYPE = CleanPreferenceEvent
1515

1616

1717
class SetCleanPreference(SetEnableCommand):
1818
"""Set clean preference command."""
1919

20-
name = "setCleanPreference"
20+
NAME = "setCleanPreference"
2121
get_command = GetCleanPreference

deebot_client/commands/json/clear_map.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class ClearMap(ExecuteCommand):
99
"""ClearMap state command."""
1010

11-
name = "clearMap"
11+
NAME = "clearMap"
1212

1313
def __init__(self) -> None:
1414
super().__init__({"type": "all"})

0 commit comments

Comments
 (0)