Set name to hyperion assets (#1822)

* set name to hyperion assets

by specifying the name in the configuration:

light kodi_xxx:
  name: "Kodi XXX"
  platform: hyperion
  host: 192.168.1.222
  port: 19444

* Update hyperion.py

fix extra space
This commit is contained in:
Chema García 2016-04-19 17:19:27 +02:00 committed by Paulus Schoutsen
parent c1ca13d613
commit b9fd4919b3

View File

@ -19,7 +19,7 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
"""Setup a Hyperion server remote.""" """Setup a Hyperion server remote."""
host = config.get(CONF_HOST, None) host = config.get(CONF_HOST, None)
port = config.get("port", 19444) port = config.get("port", 19444)
device = Hyperion(host, port) device = Hyperion(config.get('name', host), host, port)
if device.setup(): if device.setup():
add_devices_callback([device]) add_devices_callback([device])
return True return True
@ -30,11 +30,11 @@ def setup_platform(hass, config, add_devices_callback, discovery_info=None):
class Hyperion(Light): class Hyperion(Light):
"""Representation of a Hyperion remote.""" """Representation of a Hyperion remote."""
def __init__(self, host, port): def __init__(self, name, host, port):
"""Initialize the light.""" """Initialize the light."""
self._host = host self._host = host
self._port = port self._port = port
self._name = host self._name = name
self._is_available = True self._is_available = True
self._rgb_color = [255, 255, 255] self._rgb_color = [255, 255, 255]
@ -75,6 +75,7 @@ class Hyperion(Light):
"""Get the hostname of the remote.""" """Get the hostname of the remote."""
response = self.json_request({"command": "serverinfo"}) response = self.json_request({"command": "serverinfo"})
if response: if response:
if self._name == self._host:
self._name = response["info"]["hostname"] self._name = response["info"]["hostname"]
return True return True