diff --git a/homeassistant/components/philips_js/__init__.py b/homeassistant/components/philips_js/__init__.py index bfb99898ab2..11e84b6cd82 100644 --- a/homeassistant/components/philips_js/__init__.py +++ b/homeassistant/components/philips_js/__init__.py @@ -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 diff --git a/homeassistant/components/philips_js/config_flow.py b/homeassistant/components/philips_js/config_flow.py index 71bc34688b4..523918daa7c 100644 --- a/homeassistant/components/philips_js/config_flow.py +++ b/homeassistant/components/philips_js/config_flow.py @@ -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.""" diff --git a/homeassistant/components/philips_js/device_trigger.py b/homeassistant/components/philips_js/device_trigger.py index ec1da0635db..2a60a1664bc 100644 --- a/homeassistant/components/philips_js/device_trigger.py +++ b/homeassistant/components/philips_js/device_trigger.py @@ -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 diff --git a/homeassistant/components/philips_js/media_player.py b/homeassistant/components/philips_js/media_player.py index 2e263ea2891..20ef6ed9c0f 100644 --- a/homeassistant/components/philips_js/media_player.py +++ b/homeassistant/components/philips_js/media_player.py @@ -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, ) ] ) diff --git a/tests/components/philips_js/conftest.py b/tests/components/philips_js/conftest.py index 1f20cd821a5..549ad77fb06 100644 --- a/tests/components/philips_js/conftest.py +++ b/tests/components/philips_js/conftest.py @@ -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