Replace typing.Optional with new typing syntax (#97068)
parent
77f38e33e5
commit
45ec314232
|
@ -1,5 +1,5 @@
|
||||||
"""Tests for the myStrom integration."""
|
"""Tests for the myStrom integration."""
|
||||||
from typing import Any, Optional
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
def get_default_device_response(device_type: int | None) -> dict[str, Any]:
|
def get_default_device_response(device_type: int | None) -> dict[str, Any]:
|
||||||
|
@ -79,49 +79,49 @@ class MyStromBulbMock(MyStromDeviceMock):
|
||||||
self.mac = mac
|
self.mac = mac
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def firmware(self) -> Optional[str]:
|
def firmware(self) -> str | None:
|
||||||
"""Return current firmware."""
|
"""Return current firmware."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["fw_version"]
|
return self._state["fw_version"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def consumption(self) -> Optional[float]:
|
def consumption(self) -> float | None:
|
||||||
"""Return current firmware."""
|
"""Return current firmware."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["power"]
|
return self._state["power"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color(self) -> Optional[str]:
|
def color(self) -> str | None:
|
||||||
"""Return current color settings."""
|
"""Return current color settings."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["color"]
|
return self._state["color"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mode(self) -> Optional[str]:
|
def mode(self) -> str | None:
|
||||||
"""Return current mode."""
|
"""Return current mode."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["mode"]
|
return self._state["mode"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def transition_time(self) -> Optional[int]:
|
def transition_time(self) -> int | None:
|
||||||
"""Return current transition time (ramp)."""
|
"""Return current transition time (ramp)."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["ramp"]
|
return self._state["ramp"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bulb_type(self) -> Optional[str]:
|
def bulb_type(self) -> str | None:
|
||||||
"""Return the type of the bulb."""
|
"""Return the type of the bulb."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["type"]
|
return self._state["type"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self) -> Optional[bool]:
|
def state(self) -> bool | None:
|
||||||
"""Return the current state of the bulb."""
|
"""Return the current state of the bulb."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
|
@ -132,42 +132,42 @@ class MyStromSwitchMock(MyStromDeviceMock):
|
||||||
"""MyStrom Switch mock."""
|
"""MyStrom Switch mock."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def relay(self) -> Optional[bool]:
|
def relay(self) -> bool | None:
|
||||||
"""Return the relay state."""
|
"""Return the relay state."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["on"]
|
return self._state["on"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def consumption(self) -> Optional[float]:
|
def consumption(self) -> float | None:
|
||||||
"""Return the current power consumption in mWh."""
|
"""Return the current power consumption in mWh."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["power"]
|
return self._state["power"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def consumedWs(self) -> Optional[float]:
|
def consumedWs(self) -> float | None:
|
||||||
"""The average of energy consumed per second since last report call."""
|
"""The average of energy consumed per second since last report call."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["Ws"]
|
return self._state["Ws"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def firmware(self) -> Optional[str]:
|
def firmware(self) -> str | None:
|
||||||
"""Return the current firmware."""
|
"""Return the current firmware."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["version"]
|
return self._state["version"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mac(self) -> Optional[str]:
|
def mac(self) -> str | None:
|
||||||
"""Return the MAC address."""
|
"""Return the MAC address."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
return self._state["mac"]
|
return self._state["mac"]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def temperature(self) -> Optional[float]:
|
def temperature(self) -> float | None:
|
||||||
"""Return the current temperature in celsius."""
|
"""Return the current temperature in celsius."""
|
||||||
if not self._requested_state:
|
if not self._requested_state:
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import AsyncGenerator
|
from collections.abc import AsyncGenerator
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Optional
|
from typing import Any
|
||||||
|
|
||||||
from twitchAPI.object import TwitchUser
|
from twitchAPI.object import TwitchUser
|
||||||
from twitchAPI.twitch import (
|
from twitchAPI.twitch import (
|
||||||
|
@ -88,7 +88,7 @@ class TwitchMock:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def get_users(
|
async def get_users(
|
||||||
self, user_ids: Optional[list[str]] = None, logins: Optional[list[str]] = None
|
self, user_ids: list[str] | None = None, logins: list[str] | None = None
|
||||||
) -> AsyncGenerator[TwitchUser, None]:
|
) -> AsyncGenerator[TwitchUser, None]:
|
||||||
"""Get list of mock users."""
|
"""Get list of mock users."""
|
||||||
for user in [USER_OBJECT]:
|
for user in [USER_OBJECT]:
|
||||||
|
@ -101,7 +101,7 @@ class TwitchMock:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def get_users_follows(
|
async def get_users_follows(
|
||||||
self, to_id: Optional[str] = None, from_id: Optional[str] = None
|
self, to_id: str | None = None, from_id: str | None = None
|
||||||
) -> TwitchUserFollowResultMock:
|
) -> TwitchUserFollowResultMock:
|
||||||
"""Return the followers of the user."""
|
"""Return the followers of the user."""
|
||||||
if self._is_following:
|
if self._is_following:
|
||||||
|
@ -169,7 +169,7 @@ class TwitchInvalidUserMock(TwitchMock):
|
||||||
"""Twitch mock to test invalid user."""
|
"""Twitch mock to test invalid user."""
|
||||||
|
|
||||||
async def get_users(
|
async def get_users(
|
||||||
self, user_ids: Optional[list[str]] = None, logins: Optional[list[str]] = None
|
self, user_ids: list[str] | None = None, logins: list[str] | None = None
|
||||||
) -> AsyncGenerator[TwitchUser, None]:
|
) -> AsyncGenerator[TwitchUser, None]:
|
||||||
"""Get list of mock users."""
|
"""Get list of mock users."""
|
||||||
if user_ids is not None or logins is not None:
|
if user_ids is not None or logins is not None:
|
||||||
|
|
Loading…
Reference in New Issue