Add unique id property for Vizio devices so they get added to entity registry (#30497)

* add unique id property for Vizio devices so they get added to entity registry

* update requirements

* small change to make code more readable

* update to use f-string for consistency

* fix property name

* set unique_id to none if serial number couldnt be found

* set unique_id to none

* ESN should be globally unique so no device type needed. pyvizio will set ESN to None if ESN is unobtainable
This commit is contained in:
Raman Gupta 2020-01-05 05:20:06 -05:00 committed by Paulus Schoutsen
parent 30076d1843
commit 2ac5862eda
3 changed files with 9 additions and 5 deletions

View File

@ -3,7 +3,7 @@
"name": "Vizio",
"documentation": "https://www.home-assistant.io/integrations/vizio",
"requirements": [
"pyvizio==0.0.7"
"pyvizio==0.0.9"
],
"dependencies": [],
"codeowners": ["@raman325"]

View File

@ -64,9 +64,7 @@ def validate_auth(config):
token = config.get(CONF_ACCESS_TOKEN)
if config[CONF_DEVICE_CLASS] == "tv" and (token is None or token == ""):
raise vol.Invalid(
"When '{}' is 'tv' then '{}' is required.".format(
CONF_DEVICE_CLASS, CONF_ACCESS_TOKEN
),
f"When '{CONF_DEVICE_CLASS}' is 'tv' then '{CONF_ACCESS_TOKEN}' is required.",
path=[CONF_ACCESS_TOKEN],
)
return config
@ -135,6 +133,7 @@ class VizioDevice(MediaPlayerDevice):
self._supported_commands = SUPPORTED_COMMANDS[device_type]
self._device = Vizio(DEVICE_ID, host, DEFAULT_NAME, token, device_type)
self._max_volume = float(self._device.get_max_volume())
self._unique_id = self._device.get_esn()
@util.Throttle(MIN_TIME_BETWEEN_SCANS, MIN_TIME_BETWEEN_FORCED_SCANS)
def update(self):
@ -196,6 +195,11 @@ class VizioDevice(MediaPlayerDevice):
"""Flag device features that are supported."""
return self._supported_commands
@property
def unique_id(self):
"""Return the unique id of the device."""
return self._unique_id
def turn_on(self):
"""Turn the device on."""
self._device.pow_on()

View File

@ -1693,7 +1693,7 @@ pyversasense==0.0.6
pyvesync==1.1.0
# homeassistant.components.vizio
pyvizio==0.0.7
pyvizio==0.0.9
# homeassistant.components.velux
pyvlx==0.2.12