Philips JS correct post review comments (#47247)

This commit is contained in:
Joakim Plate 2021-03-03 18:51:58 +01:00 committed by GitHub
parent 099c9c59cb
commit 7626aa5c94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 23 deletions

View file

@ -725,6 +725,7 @@ omit =
homeassistant/components/pencom/switch.py
homeassistant/components/philips_js/__init__.py
homeassistant/components/philips_js/media_player.py
homeassistant/components/philips_js/remote.py
homeassistant/components/pi_hole/sensor.py
homeassistant/components/pi4ioe5v9xxxx/binary_sensor.py
homeassistant/components/pi4ioe5v9xxxx/switch.py

View file

@ -150,7 +150,7 @@ class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
and self.api.on
and self.api.notify_change_supported
):
self._notify_future = self.hass.loop.create_task(self._notify_task())
self._notify_future = asyncio.create_task(self._notify_task())
@callback
def async_remove_listener(self, update_callback: CALLBACK_TYPE) -> None:

View file

@ -1,6 +1,6 @@
"""Config flow for Philips TV integration."""
import platform
from typing import Any, Dict, Optional, Tuple, TypedDict
from typing import Any, Dict, Optional, Tuple
from haphilipsjs import ConnectionFailure, PairingFailure, PhilipsTV
import voluptuous as vol
@ -23,12 +23,6 @@ from .const import ( # pylint:disable=unused-import
)
class FlowUserDict(TypedDict):
"""Data for user step."""
host: str
async def validate_input(
hass: core.HomeAssistant, host: str, api_version: int
) -> Tuple[Dict, PhilipsTV]:
@ -50,11 +44,14 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
VERSION = 1
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
_current = {}
_hub: PhilipsTV
_pair_state: Any
def __init__(self) -> None:
"""Initialize flow."""
super().__init__()
self._current = {}
self._hub: Optional[PhilipsTV] = None
self._pair_state: Any = None
async def async_step_import(self, conf: Dict[str, Any]):
async def async_step_import(self, conf: dict) -> dict:
"""Import a configuration from config.yaml."""
for entry in self._async_current_entries():
if entry.data[CONF_HOST] == conf[CONF_HOST]:
@ -75,7 +72,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
data=self._current,
)
async def async_step_pair(self, user_input: Optional[Dict] = None):
async def async_step_pair(self, user_input: Optional[dict] = None) -> dict:
"""Attempt to pair with device."""
assert self._hub
@ -96,7 +93,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"native",
)
except PairingFailure as exc:
LOGGER.debug(str(exc))
LOGGER.debug(exc)
return self.async_abort(
reason="pairing_failure",
description_placeholders={"error_id": exc.data.get("error_id")},
@ -110,7 +107,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self._pair_state, user_input[CONF_PIN]
)
except PairingFailure as exc:
LOGGER.debug(str(exc))
LOGGER.debug(exc)
if exc.data.get("error_id") == "INVALID_PIN":
errors[CONF_PIN] = "invalid_pin"
return self.async_show_form(
@ -126,7 +123,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self._current[CONF_PASSWORD] = password
return await self._async_create_current()
async def async_step_user(self, user_input: Optional[FlowUserDict] = None):
async def async_step_user(self, user_input: Optional[dict] = None) -> dict:
"""Handle the initial step."""
errors = {}
if user_input:
@ -136,7 +133,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self.hass, user_input[CONF_HOST], user_input[CONF_API_VERSION]
)
except ConnectionFailure as exc:
LOGGER.error(str(exc))
LOGGER.error(exc)
errors["base"] = "cannot_connect"
except Exception: # pylint: disable=broad-except
LOGGER.exception("Unexpected exception")

View file

@ -295,8 +295,8 @@ class PhilipsTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
def media_image_url(self):
"""Image url of current playing media."""
if self._media_content_id and self._media_content_type in (
MEDIA_CLASS_APP,
MEDIA_CLASS_CHANNEL,
MEDIA_TYPE_APP,
MEDIA_TYPE_CHANNEL,
):
return self.get_browse_image_url(
self._media_content_type, self._media_content_id, media_image_id=None
@ -384,7 +384,7 @@ class PhilipsTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
media_class=MEDIA_CLASS_DIRECTORY,
media_content_id="channels",
media_content_type=MEDIA_TYPE_CHANNELS,
children_media_class=MEDIA_TYPE_CHANNEL,
children_media_class=MEDIA_CLASS_CHANNEL,
can_play=False,
can_expand=True,
children=children,
@ -427,7 +427,7 @@ class PhilipsTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
media_class=MEDIA_CLASS_DIRECTORY,
media_content_id=f"favorites/{list_id}",
media_content_type=MEDIA_TYPE_CHANNELS,
children_media_class=MEDIA_TYPE_CHANNEL,
children_media_class=MEDIA_CLASS_CHANNEL,
can_play=False,
can_expand=True,
children=children,
@ -458,7 +458,7 @@ class PhilipsTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
media_class=MEDIA_CLASS_DIRECTORY,
media_content_id="applications",
media_content_type=MEDIA_TYPE_APPS,
children_media_class=MEDIA_TYPE_APP,
children_media_class=MEDIA_CLASS_APP,
can_play=False,
can_expand=True,
children=children,
@ -479,7 +479,7 @@ class PhilipsTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
media_class=MEDIA_CLASS_DIRECTORY,
media_content_id="favorite_lists",
media_content_type=MEDIA_TYPE_CHANNELS,
children_media_class=MEDIA_TYPE_CHANNEL,
children_media_class=MEDIA_CLASS_CHANNEL,
can_play=False,
can_expand=True,
children=children,