Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Executor bug that happens for Python 3.8 installations #685

Merged
merged 2 commits into from
Dec 20, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions custom_components/tahoma/executor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Class for helpers and community with the OverKiz API."""
from __future__ import annotations

import logging
from typing import Any, Optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional does not exist? I don't get it

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional wasn't part of my original change, the main issue is that list is supported in Python 3.9, where it is called List in Python 3.8.

After importing from future, it seems that importing Optional is not required anymore.

from typing import Any
from urllib.parse import urlparse

from pyhoma.models import Command, Device
Expand All @@ -24,7 +26,7 @@ def device(self) -> Device:
"""Return Overkiz device linked to this entity."""
return self.coordinator.data[self.device_url]

def select_command(self, *commands: str) -> Optional[str]:
def select_command(self, *commands: str) -> str | None:
"""Select first existing command in a list of commands."""
existing_commands = self.device.definition.commands
return next((c for c in commands if c in existing_commands), None)
Expand All @@ -33,7 +35,7 @@ def has_command(self, *commands: str) -> bool:
"""Return True if a command exists in a list of commands."""
return self.select_command(*commands) is not None

def select_state(self, *states) -> Optional[str]:
def select_state(self, *states) -> str | None:
"""Select first existing active state in a list of states."""
if self.device.states:
return next(
Expand All @@ -50,7 +52,7 @@ def has_state(self, *states: str) -> bool:
"""Return True if a state exists in self."""
return self.select_state(*states) is not None

def select_attribute(self, *attributes) -> Optional[str]:
def select_attribute(self, *attributes) -> str | None:
"""Select first existing active state in a list of states."""
if self.device.attributes:
return next(
Expand Down