Use HassKey in ps4 (#144868)

This commit is contained in:
epenet 2025-05-14 11:51:32 +02:00 committed by GitHub
parent 063deab3cb
commit 4287df5f3d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 9 deletions

View File

@ -1,9 +1,13 @@
"""Support for PlayStation 4 consoles."""
from __future__ import annotations
from dataclasses import dataclass
import logging
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
import voluptuous as vol
@ -41,6 +45,9 @@ from .const import (
PS4_DATA,
)
if TYPE_CHECKING:
from .media_player import PS4Device
_LOGGER = logging.getLogger(__name__)
SERVICE_COMMAND = "send_command"
@ -57,21 +64,21 @@ PLATFORMS = [Platform.MEDIA_PLAYER]
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
@dataclass
class PS4Data:
"""Init Data Class."""
def __init__(self):
"""Init Class."""
self.devices = []
self.protocol = None
devices: list[PS4Device]
protocol: DDPProtocol
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
"""Set up the PS4 Component."""
hass.data[PS4_DATA] = PS4Data()
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)
service_handle(hass)
return True

View File

@ -1,5 +1,14 @@
"""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"
CONFIG_ENTRY_VERSION = 3
DEFAULT_NAME = "PlayStation 4"
@ -7,7 +16,7 @@ DEFAULT_REGION = "United States"
DEFAULT_ALIAS = "Home-Assistant"
DOMAIN = "ps4"
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")