-
-
Notifications
You must be signed in to change notification settings - Fork 37.8k
Add remote control platform to Panasonic Viera #42275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
41c52a6
a39f65d
6f7be1d
d2f2b5d
8b0c34d
1ecc602
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,8 @@ | |
| ATTR_MODEL_NUMBER, | ||
| ATTR_REMOTE, | ||
| ATTR_UDN, | ||
| DEFAULT_MANUFACTURER, | ||
| DEFAULT_MODEL_NUMBER, | ||
| DOMAIN, | ||
| ) | ||
|
|
||
|
|
@@ -69,11 +71,11 @@ def __init__(self, remote, name, device_info): | |
| self._device_info = device_info | ||
|
|
||
| @property | ||
| def unique_id(self) -> str: | ||
| def unique_id(self): | ||
| """Return the unique ID of the device.""" | ||
| if self._device_info is not None: | ||
| return self._device_info[ATTR_UDN] | ||
| return None | ||
| if self._device_info is None: | ||
| return None | ||
| return self._device_info[ATTR_UDN] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is still a UUID in the response by Tom, isn't that the same as UDN ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually the problem was that his TV apparently has no model number explicit in the descriptor file the unique id was ok (I think) |
||
|
|
||
| @property | ||
| def device_info(self): | ||
|
|
@@ -83,8 +85,10 @@ def device_info(self): | |
| return { | ||
| "name": self._name, | ||
| "identifiers": {(DOMAIN, self._device_info[ATTR_UDN])}, | ||
| "manufacturer": self._device_info[ATTR_MANUFACTURER], | ||
| "model": self._device_info[ATTR_MODEL_NUMBER], | ||
| "manufacturer": self._device_info.get( | ||
| ATTR_MANUFACTURER, DEFAULT_MANUFACTURER | ||
| ), | ||
| "model": self._device_info.get(ATTR_MODEL_NUMBER, DEFAULT_MODEL_NUMBER), | ||
| } | ||
|
|
||
| @property | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """Remote control support for Panasonic Viera TV.""" | ||
| import logging | ||
|
|
||
| from homeassistant.components.remote import RemoteEntity | ||
| from homeassistant.const import CONF_NAME, STATE_ON | ||
|
|
||
| from .const import ( | ||
| ATTR_DEVICE_INFO, | ||
| ATTR_MANUFACTURER, | ||
| ATTR_MODEL_NUMBER, | ||
| ATTR_REMOTE, | ||
| ATTR_UDN, | ||
| DEFAULT_MANUFACTURER, | ||
| DEFAULT_MODEL_NUMBER, | ||
| DOMAIN, | ||
| ) | ||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def async_setup_entry(hass, config_entry, async_add_entities): | ||
| """Set up Panasonic Viera TV Remote from a config entry.""" | ||
|
|
||
| config = config_entry.data | ||
|
|
||
| remote = hass.data[DOMAIN][config_entry.entry_id][ATTR_REMOTE] | ||
| name = config[CONF_NAME] | ||
| device_info = config[ATTR_DEVICE_INFO] | ||
|
|
||
| remote_device = PanasonicVieraRemoteEntity(remote, name, device_info) | ||
| async_add_entities([remote_device]) | ||
|
|
||
|
|
||
| class PanasonicVieraRemoteEntity(RemoteEntity): | ||
| """Representation of a Panasonic Viera TV Remote.""" | ||
|
|
||
| def __init__(self, remote, name, device_info): | ||
| """Initialize the entity.""" | ||
| # Save a reference to the imported class | ||
| self._remote = remote | ||
| self._name = name | ||
| self._device_info = device_info | ||
|
|
||
| @property | ||
| def unique_id(self): | ||
| """Return the unique ID of the device.""" | ||
| if self._device_info is None: | ||
| return None | ||
| return self._device_info[ATTR_UDN] | ||
|
|
||
| @property | ||
| def device_info(self): | ||
| """Return device specific attributes.""" | ||
| if self._device_info is None: | ||
| return None | ||
| return { | ||
| "name": self._name, | ||
| "identifiers": {(DOMAIN, self._device_info[ATTR_UDN])}, | ||
| "manufacturer": self._device_info.get( | ||
| ATTR_MANUFACTURER, DEFAULT_MANUFACTURER | ||
| ), | ||
| "model": self._device_info.get(ATTR_MODEL_NUMBER, DEFAULT_MODEL_NUMBER), | ||
| } | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the device.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def available(self): | ||
| """Return True if the device is available.""" | ||
| return self._remote.available | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if device is on.""" | ||
| return self._remote.state == STATE_ON | ||
|
|
||
| async def async_turn_on(self, **kwargs): | ||
| """Turn the device on.""" | ||
| await self._remote.async_turn_on() | ||
|
|
||
| async def async_turn_off(self, **kwargs): | ||
| """Turn the device off.""" | ||
| await self._remote.async_turn_off() | ||
|
|
||
| async def async_send_command(self, command, **kwargs): | ||
| """Send a command to one device.""" | ||
| for cmd in command: | ||
| await self._remote.async_send_key(cmd) |
Uh oh!
There was an error while loading. Please reload this page.