Correct errors found on post merge review in philips_js (#46428)

* Correct missed review changes

* Adjust return value for device trigger

* Drop cannot connect

* Always assume there is a unique id

* No need to yield

* Update homeassistant/components/philips_js/media_player.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Move typing to init

* Adjust typing instead of returning lambda

* Explicity return None

* Coerce into int

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Joakim Plate 2021-02-12 02:35:29 +01:00 committed by GitHub
parent ee04473e85
commit a67b598971
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 23 deletions

View File

@ -64,11 +64,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
class PluggableAction:
"""A pluggable action handler."""
_actions: Dict[Any, AutomationActionType] = {}
def __init__(self, update: Callable[[], None]):
"""Initialize."""
self._update = update
self._actions: Dict[Any, AutomationActionType] = {}
def __bool__(self):
"""Return if we have something attached."""
@ -101,8 +100,6 @@ class PluggableAction:
class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
"""Coordinator to update data."""
api: PhilipsTV
def __init__(self, hass, api: PhilipsTV) -> None:
"""Set up the coordinator."""
self.api = api
@ -113,19 +110,19 @@ class PhilipsTVDataUpdateCoordinator(DataUpdateCoordinator[None]):
self.turn_on = PluggableAction(_update_listeners)
async def _async_update():
try:
await self.hass.async_add_executor_job(self.api.update)
except ConnectionFailure:
pass
super().__init__(
hass,
LOGGER,
name=DOMAIN,
update_method=_async_update,
update_interval=timedelta(seconds=30),
request_refresh_debouncer=Debouncer(
hass, LOGGER, cooldown=2.0, immediate=False
),
)
async def _async_update_data(self):
"""Fetch the latest data from the source."""
try:
await self.hass.async_add_executor_job(self.api.update)
except ConnectionFailure:
pass

View File

@ -5,7 +5,7 @@ from typing import Any, Dict, Optional, TypedDict
from haphilipsjs import ConnectionFailure, PhilipsTV
import voluptuous as vol
from homeassistant import config_entries, core, exceptions
from homeassistant import config_entries, core
from homeassistant.const import CONF_API_VERSION, CONF_HOST
from .const import DOMAIN # pylint:disable=unused-import
@ -84,7 +84,3 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
}
)
return self.async_show_form(step_id="user", data_schema=schema, errors=errors)
class CannotConnect(exceptions.HomeAssistantError):
"""Error to indicate we cannot connect."""

View File

@ -1,5 +1,5 @@
"""Provides device automations for control of device."""
from typing import List
from typing import List, Optional
import voluptuous as vol
@ -43,7 +43,7 @@ async def async_attach_trigger(
config: ConfigType,
action: AutomationActionType,
automation_info: dict,
) -> CALLBACK_TYPE:
) -> Optional[CALLBACK_TYPE]:
"""Attach a trigger."""
registry: DeviceRegistry = await async_get_registry(hass)
if config[CONF_TYPE] == TRIGGER_TYPE_TURN_ON:
@ -63,3 +63,5 @@ async def async_attach_trigger(
)
if coordinator:
return coordinator.turn_on.async_attach(action, variables)
return None

View File

@ -57,7 +57,7 @@ SUPPORT_PHILIPS_JS = (
CONF_ON_ACTION = "turn_on_action"
DEFAULT_API_VERSION = "1"
DEFAULT_API_VERSION = 1
PREFIX_SEPARATOR = ": "
PREFIX_SOURCE = "Input"
@ -72,7 +72,9 @@ PLATFORM_SCHEMA = vol.All(
{
vol.Required(CONF_HOST): cv.string,
vol.Remove(CONF_NAME): cv.string,
vol.Optional(CONF_API_VERSION, default=DEFAULT_API_VERSION): cv.string,
vol.Optional(CONF_API_VERSION, default=DEFAULT_API_VERSION): vol.Coerce(
int
),
vol.Remove(CONF_ON_ACTION): cv.SCRIPT_SCHEMA,
}
),
@ -83,7 +85,7 @@ def _inverted(data):
return {v: k for k, v in data.items()}
def setup_platform(hass, config, add_entities, discovery_info=None):
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Philips TV platform."""
hass.async_create_task(
hass.config_entries.flow.async_init(
@ -106,7 +108,7 @@ async def async_setup_entry(
PhilipsTVMediaPlayer(
coordinator,
config_entry.data[CONF_SYSTEM],
config_entry.unique_id or config_entry.entry_id,
config_entry.unique_id,
)
]
)

View File

@ -50,7 +50,7 @@ async def mock_entity(hass, mock_device_reg, mock_config_entry):
"""Get standard player."""
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
await hass.async_block_till_done()
yield MOCK_ENTITY_ID
return MOCK_ENTITY_ID
@fixture