mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 07:37:34 +00:00
Use HassKey in ps4 (#144868)
This commit is contained in:
parent
063deab3cb
commit
4287df5f3d
@ -1,9 +1,13 @@
|
|||||||
"""Support for PlayStation 4 consoles."""
|
"""Support for PlayStation 4 consoles."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from dataclasses import dataclass
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from pyps4_2ndscreen.ddp import async_create_ddp_endpoint
|
from pyps4_2ndscreen.ddp import DDPProtocol, async_create_ddp_endpoint
|
||||||
from pyps4_2ndscreen.media_art import COUNTRIES
|
from pyps4_2ndscreen.media_art import COUNTRIES
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -41,6 +45,9 @@ from .const import (
|
|||||||
PS4_DATA,
|
PS4_DATA,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from .media_player import PS4Device
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SERVICE_COMMAND = "send_command"
|
SERVICE_COMMAND = "send_command"
|
||||||
@ -57,21 +64,21 @@ PLATFORMS = [Platform.MEDIA_PLAYER]
|
|||||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
class PS4Data:
|
class PS4Data:
|
||||||
"""Init Data Class."""
|
"""Init Data Class."""
|
||||||
|
|
||||||
def __init__(self):
|
devices: list[PS4Device]
|
||||||
"""Init Class."""
|
protocol: DDPProtocol
|
||||||
self.devices = []
|
|
||||||
self.protocol = None
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the PS4 Component."""
|
"""Set up the PS4 Component."""
|
||||||
hass.data[PS4_DATA] = PS4Data()
|
|
||||||
|
|
||||||
transport, protocol = await async_create_ddp_endpoint()
|
transport, protocol = await async_create_ddp_endpoint()
|
||||||
hass.data[PS4_DATA].protocol = protocol
|
hass.data[PS4_DATA] = PS4Data(
|
||||||
|
devices=[],
|
||||||
|
protocol=protocol,
|
||||||
|
)
|
||||||
_LOGGER.debug("PS4 DDP endpoint created: %s, %s", transport, protocol)
|
_LOGGER.debug("PS4 DDP endpoint created: %s, %s", transport, protocol)
|
||||||
service_handle(hass)
|
service_handle(hass)
|
||||||
return True
|
return True
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
"""Constants for PlayStation 4."""
|
"""Constants for PlayStation 4."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
from homeassistant.util.hass_dict import HassKey
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from . import PS4Data
|
||||||
|
|
||||||
ATTR_MEDIA_IMAGE_URL = "media_image_url"
|
ATTR_MEDIA_IMAGE_URL = "media_image_url"
|
||||||
CONFIG_ENTRY_VERSION = 3
|
CONFIG_ENTRY_VERSION = 3
|
||||||
DEFAULT_NAME = "PlayStation 4"
|
DEFAULT_NAME = "PlayStation 4"
|
||||||
@ -7,7 +16,7 @@ DEFAULT_REGION = "United States"
|
|||||||
DEFAULT_ALIAS = "Home-Assistant"
|
DEFAULT_ALIAS = "Home-Assistant"
|
||||||
DOMAIN = "ps4"
|
DOMAIN = "ps4"
|
||||||
GAMES_FILE = ".ps4-games.{}.json"
|
GAMES_FILE = ".ps4-games.{}.json"
|
||||||
PS4_DATA = "ps4_data"
|
PS4_DATA: HassKey[PS4Data] = HassKey(DOMAIN)
|
||||||
|
|
||||||
COMMANDS = ("up", "down", "right", "left", "enter", "back", "option", "ps", "ps_hold")
|
COMMANDS = ("up", "down", "right", "left", "enter", "back", "option", "ps", "ps_hold")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user