Use attrs instead of properties in Bravia TV integration (#52045)
* Use attrs instead of properties * Revert to using properties for dynamic data * Move volume_level to coordinator * Move media_title to coordinator * Remove unused variables * Fix variable name * Revert removed variables
This commit is contained in:
parent
80ae346318
commit
75faee4f25
3 changed files with 19 additions and 49 deletions
|
@ -71,9 +71,9 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
|
||||||
self.pin = pin
|
self.pin = pin
|
||||||
self.ignored_sources = ignored_sources
|
self.ignored_sources = ignored_sources
|
||||||
self.muted = False
|
self.muted = False
|
||||||
self.program_name = None
|
|
||||||
self.channel_name = None
|
self.channel_name = None
|
||||||
self.channel_number = None
|
self.channel_number = None
|
||||||
|
self.media_title = None
|
||||||
self.source = None
|
self.source = None
|
||||||
self.source_list = []
|
self.source_list = []
|
||||||
self.original_content_list = []
|
self.original_content_list = []
|
||||||
|
@ -85,7 +85,7 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
|
||||||
self.audio_output = None
|
self.audio_output = None
|
||||||
self.min_volume = None
|
self.min_volume = None
|
||||||
self.max_volume = None
|
self.max_volume = None
|
||||||
self.volume = None
|
self.volume_level = None
|
||||||
self.is_on = False
|
self.is_on = False
|
||||||
# Assume that the TV is in Play mode
|
# Assume that the TV is in Play mode
|
||||||
self.playing = True
|
self.playing = True
|
||||||
|
@ -117,8 +117,9 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
|
||||||
"""Refresh volume information."""
|
"""Refresh volume information."""
|
||||||
volume_info = self.braviarc.get_volume_info(self.audio_output)
|
volume_info = self.braviarc.get_volume_info(self.audio_output)
|
||||||
if volume_info is not None:
|
if volume_info is not None:
|
||||||
|
volume = volume_info.get("volume")
|
||||||
|
self.volume_level = volume / 100 if volume is not None else None
|
||||||
self.audio_output = volume_info.get("target")
|
self.audio_output = volume_info.get("target")
|
||||||
self.volume = volume_info.get("volume")
|
|
||||||
self.min_volume = volume_info.get("minVolume")
|
self.min_volume = volume_info.get("minVolume")
|
||||||
self.max_volume = volume_info.get("maxVolume")
|
self.max_volume = volume_info.get("maxVolume")
|
||||||
self.muted = volume_info.get("mute")
|
self.muted = volume_info.get("mute")
|
||||||
|
@ -140,7 +141,7 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
|
||||||
def _refresh_playing_info(self):
|
def _refresh_playing_info(self):
|
||||||
"""Refresh playing information."""
|
"""Refresh playing information."""
|
||||||
playing_info = self.braviarc.get_playing_info()
|
playing_info = self.braviarc.get_playing_info()
|
||||||
self.program_name = playing_info.get("programTitle")
|
program_name = playing_info.get("programTitle")
|
||||||
self.channel_name = playing_info.get("title")
|
self.channel_name = playing_info.get("title")
|
||||||
self.program_media_type = playing_info.get("programMediaType")
|
self.program_media_type = playing_info.get("programMediaType")
|
||||||
self.channel_number = playing_info.get("dispNum")
|
self.channel_number = playing_info.get("dispNum")
|
||||||
|
@ -150,6 +151,12 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]):
|
||||||
self.start_date_time = playing_info.get("startDateTime")
|
self.start_date_time = playing_info.get("startDateTime")
|
||||||
if not playing_info:
|
if not playing_info:
|
||||||
self.channel_name = "App"
|
self.channel_name = "App"
|
||||||
|
if self.channel_name is not None:
|
||||||
|
self.media_title = self.channel_name
|
||||||
|
if program_name is not None:
|
||||||
|
self.media_title = f"{self.media_title}: {program_name}"
|
||||||
|
else:
|
||||||
|
self.media_title = None
|
||||||
|
|
||||||
def _update_tv_data(self):
|
def _update_tv_data(self):
|
||||||
"""Connect and update TV info."""
|
"""Connect and update TV info."""
|
||||||
|
|
|
@ -116,27 +116,12 @@ class BraviaTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
|
||||||
def __init__(self, coordinator, name, unique_id, device_info):
|
def __init__(self, coordinator, name, unique_id, device_info):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
|
|
||||||
self._name = name
|
self._attr_device_info = device_info
|
||||||
self._unique_id = unique_id
|
self._attr_name = name
|
||||||
self._device_info = device_info
|
self._attr_unique_id = unique_id
|
||||||
|
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return a unique_id for this entity."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return the device info."""
|
|
||||||
return self._device_info
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the device."""
|
"""Return the state of the device."""
|
||||||
|
@ -157,9 +142,7 @@ class BraviaTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
|
||||||
@property
|
@property
|
||||||
def volume_level(self):
|
def volume_level(self):
|
||||||
"""Volume level of the media player (0..1)."""
|
"""Volume level of the media player (0..1)."""
|
||||||
if self.coordinator.volume is not None:
|
return self.coordinator.volume_level
|
||||||
return self.coordinator.volume / 100
|
|
||||||
return None
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_volume_muted(self):
|
def is_volume_muted(self):
|
||||||
|
@ -169,12 +152,7 @@ class BraviaTVMediaPlayer(CoordinatorEntity, MediaPlayerEntity):
|
||||||
@property
|
@property
|
||||||
def media_title(self):
|
def media_title(self):
|
||||||
"""Title of current playing media."""
|
"""Title of current playing media."""
|
||||||
return_value = None
|
return self.coordinator.media_title
|
||||||
if self.coordinator.channel_name is not None:
|
|
||||||
return_value = self.coordinator.channel_name
|
|
||||||
if self.coordinator.program_name is not None:
|
|
||||||
return_value = f"{return_value}: {self.coordinator.program_name}"
|
|
||||||
return return_value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def media_content_id(self):
|
def media_content_id(self):
|
||||||
|
|
|
@ -29,27 +29,12 @@ class BraviaTVRemote(CoordinatorEntity, RemoteEntity):
|
||||||
def __init__(self, coordinator, name, unique_id, device_info):
|
def __init__(self, coordinator, name, unique_id, device_info):
|
||||||
"""Initialize the entity."""
|
"""Initialize the entity."""
|
||||||
|
|
||||||
self._name = name
|
self._attr_device_info = device_info
|
||||||
self._unique_id = unique_id
|
self._attr_name = name
|
||||||
self._device_info = device_info
|
self._attr_unique_id = unique_id
|
||||||
|
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
|
|
||||||
@property
|
|
||||||
def unique_id(self):
|
|
||||||
"""Return the unique ID of the device."""
|
|
||||||
return self._unique_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def device_info(self):
|
|
||||||
"""Return device specific attributes."""
|
|
||||||
return self._device_info
|
|
||||||
|
|
||||||
@property
|
|
||||||
def name(self):
|
|
||||||
"""Return the name of the device."""
|
|
||||||
return self._name
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return true if device is on."""
|
"""Return true if device is on."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue