mirror of
https://github.com/home-assistant/core.git
synced 2025-09-06 13:21:33 +02:00
Add info to Bravia device (#150690)
This commit is contained in:
committed by
GitHub
parent
7fba94747e
commit
90558c517b
@@ -53,8 +53,7 @@ async def async_setup_entry(
|
||||
assert unique_id is not None
|
||||
|
||||
async_add_entities(
|
||||
BraviaTVButton(coordinator, unique_id, config_entry.title, description)
|
||||
for description in BUTTONS
|
||||
BraviaTVButton(coordinator, unique_id, description) for description in BUTTONS
|
||||
)
|
||||
|
||||
|
||||
@@ -67,11 +66,10 @@ class BraviaTVButton(BraviaTVEntity, ButtonEntity):
|
||||
self,
|
||||
coordinator: BraviaTVCoordinator,
|
||||
unique_id: str,
|
||||
model: str,
|
||||
description: BraviaTVButtonDescription,
|
||||
) -> None:
|
||||
"""Initialize the button."""
|
||||
super().__init__(coordinator, unique_id, model)
|
||||
super().__init__(coordinator, unique_id)
|
||||
self._attr_unique_id = f"{unique_id}_{description.key}"
|
||||
self.entity_description = description
|
||||
|
||||
|
@@ -79,14 +79,16 @@ class BraviaTVConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
system_info = await self.client.get_system_info()
|
||||
cid = system_info[ATTR_CID].lower()
|
||||
title = system_info[ATTR_MODEL]
|
||||
|
||||
self.device_config[CONF_MAC] = system_info[ATTR_MAC]
|
||||
|
||||
await self.async_set_unique_id(cid)
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
return self.async_create_entry(title=title, data=self.device_config)
|
||||
return self.async_create_entry(
|
||||
title=f"{system_info['name']} {system_info[ATTR_MODEL]}",
|
||||
data=self.device_config,
|
||||
)
|
||||
|
||||
async def async_reauth_device(self) -> ConfigFlowResult:
|
||||
"""Reauthorize Bravia TV device from config."""
|
||||
|
@@ -81,6 +81,7 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
|
||||
self.use_psk = config_entry.data.get(CONF_USE_PSK, False)
|
||||
self.client_id = config_entry.data.get(CONF_CLIENT_ID, LEGACY_CLIENT_ID)
|
||||
self.nickname = config_entry.data.get(CONF_NICKNAME, NICKNAME_PREFIX)
|
||||
self.system_info: dict[str, str] = {}
|
||||
self.source: str | None = None
|
||||
self.source_list: list[str] = []
|
||||
self.source_map: dict[str, dict] = {}
|
||||
@@ -150,6 +151,9 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
|
||||
self.is_on = power_status == "active"
|
||||
self.skipped_updates = 0
|
||||
|
||||
if not self.system_info:
|
||||
self.system_info = await self.client.get_system_info()
|
||||
|
||||
if self.is_on is False:
|
||||
return
|
||||
|
||||
|
@@ -12,23 +12,16 @@ class BraviaTVEntity(CoordinatorEntity[BraviaTVCoordinator]):
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: BraviaTVCoordinator,
|
||||
unique_id: str,
|
||||
model: str,
|
||||
) -> None:
|
||||
def __init__(self, coordinator: BraviaTVCoordinator, unique_id: str) -> None:
|
||||
"""Initialize the entity."""
|
||||
super().__init__(coordinator)
|
||||
|
||||
self._attr_unique_id = unique_id
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, unique_id)},
|
||||
connections={(CONNECTION_NETWORK_MAC, coordinator.system_info["macAddr"])},
|
||||
manufacturer=ATTR_MANUFACTURER,
|
||||
model=model,
|
||||
name=f"{ATTR_MANUFACTURER} {model}",
|
||||
model_id=coordinator.system_info["model"],
|
||||
hw_version=coordinator.system_info["generation"],
|
||||
serial_number=coordinator.system_info["serial"],
|
||||
)
|
||||
if coordinator.client.mac is not None:
|
||||
self._attr_device_info["connections"] = {
|
||||
(CONNECTION_NETWORK_MAC, coordinator.client.mac)
|
||||
}
|
||||
|
@@ -34,9 +34,7 @@ async def async_setup_entry(
|
||||
unique_id = config_entry.unique_id
|
||||
assert unique_id is not None
|
||||
|
||||
async_add_entities(
|
||||
[BraviaTVMediaPlayer(coordinator, unique_id, config_entry.title)]
|
||||
)
|
||||
async_add_entities([BraviaTVMediaPlayer(coordinator, unique_id)])
|
||||
|
||||
|
||||
class BraviaTVMediaPlayer(BraviaTVEntity, MediaPlayerEntity):
|
||||
|
@@ -24,7 +24,7 @@ async def async_setup_entry(
|
||||
unique_id = config_entry.unique_id
|
||||
assert unique_id is not None
|
||||
|
||||
async_add_entities([BraviaTVRemote(coordinator, unique_id, config_entry.title)])
|
||||
async_add_entities([BraviaTVRemote(coordinator, unique_id)])
|
||||
|
||||
|
||||
class BraviaTVRemote(BraviaTVEntity, RemoteEntity):
|
||||
|
@@ -21,7 +21,7 @@
|
||||
'source': 'user',
|
||||
'subentries': list([
|
||||
]),
|
||||
'title': 'Mock Title',
|
||||
'title': 'BRAVIA TV-Model',
|
||||
'unique_id': 'very_unique_string',
|
||||
'version': 1,
|
||||
}),
|
||||
|
@@ -143,7 +143,7 @@ async def test_ssdp_discovery(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].unique_id == "very_unique_string"
|
||||
assert result["title"] == "TV-Model"
|
||||
assert result["title"] == "BRAVIA TV-Model"
|
||||
assert result["data"] == {
|
||||
CONF_HOST: "bravia-host",
|
||||
CONF_PIN: "1234",
|
||||
@@ -340,7 +340,7 @@ async def test_create_entry(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].unique_id == "very_unique_string"
|
||||
assert result["title"] == "TV-Model"
|
||||
assert result["title"] == "BRAVIA TV-Model"
|
||||
assert result["data"] == {
|
||||
CONF_HOST: "bravia-host",
|
||||
CONF_PIN: "1234",
|
||||
@@ -381,7 +381,7 @@ async def test_create_entry_psk(hass: HomeAssistant) -> None:
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["result"].unique_id == "very_unique_string"
|
||||
assert result["title"] == "TV-Model"
|
||||
assert result["title"] == "BRAVIA TV-Model"
|
||||
assert result["data"] == {
|
||||
CONF_HOST: "bravia-host",
|
||||
CONF_PIN: "mypsk",
|
||||
|
@@ -46,6 +46,7 @@ async def test_entry_diagnostics(
|
||||
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
title="BRAVIA TV-Model",
|
||||
data={
|
||||
CONF_HOST: "localhost",
|
||||
CONF_MAC: "AA:BB:CC:DD:EE:FF",
|
||||
|
Reference in New Issue
Block a user