Skip to content
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

Override nodeid from config #2

Merged
merged 2 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ switch:
host: 192.168.1.XXX
username: !secret philips_username
password: !secret philips_password
id: 2131230774 # ambilight_hue_off node id. Default is 2131230774, but some newer TVs use 2131230778 instead.
scan_interval: 5
```

If the component is not working, try setting `2131230778` as the `id` in the config

*note:* there is often a noticeable lag between Home Assistant sending the request to toggle the setting, and receiving a status update from the API, for this reason, it is advised that you reduce your `scan_interval` (in seconds) to suit your needs.

32 changes: 18 additions & 14 deletions custom_components/philips_ambilight+hue/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import voluptuous as vol
from homeassistant.components.switch import (
DOMAIN, PLATFORM_SCHEMA, SwitchDevice, ENTITY_ID_FORMAT)
from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_USERNAME, CONF_PASSWORD, STATE_OFF, STATE_STANDBY, STATE_ON)
from homeassistant.const import (CONF_HOST, CONF_NAME, CONF_USERNAME, CONF_PASSWORD, CONF_ID, STATE_OFF, STATE_STANDBY, STATE_ON)
from requests.auth import HTTPDigestAuth
from requests.adapters import HTTPAdapter

Expand All @@ -14,31 +14,35 @@
DEFAULT_USER = 'user'
DEFAULT_PASS = 'pass'
DEFAULT_NAME = 'Ambilight+Hue'
DEFAULT_ID = '2131230774'
BASE_URL = 'https://{0}:1926/6/{1}' # for older philps tv's, try changing this to 'http://{0}:1925/1/{1}'
TIMEOUT = 5.0
CONNFAILCOUNT = 5

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string,
vol.Required(CONF_USERNAME, default=DEFAULT_USER): cv.string,
vol.Required(CONF_PASSWORD, default=DEFAULT_PASS): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string
vol.Required(CONF_HOST, default=DEFAULT_HOST): cv.string,
vol.Required(CONF_USERNAME, default=DEFAULT_USER): cv.string,
vol.Required(CONF_PASSWORD, default=DEFAULT_PASS): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_ID, default=DEFAULT_ID): cv.string
})

def setup_platform(hass, config, add_devices, discovery_info=None):
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
user = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
add_devices([AmbiHue(name, host, user, password)])
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
user = config.get(CONF_USERNAME)
password = config.get(CONF_PASSWORD)
nodeId = config.get(CONF_ID)
add_devices([AmbiHue(name, host, user, password, nodeId)])

class AmbiHue(SwitchDevice):

def __init__(self, name, host, user, password):
def __init__(self, name, host, user, password, nodeId):
self._name = name
self._host = host
self._user = user
self._password = password
self._nodeId = int(nodeId)
self._state = False
self._connfail = 0
self._available = False
Expand All @@ -63,15 +67,15 @@ def should_poll(self):


def turn_on(self, **kwargs):
self._postReq('menuitems/settings/update', {"values":[{"value":{"Nodeid":2131230774,"Controllable":"true","Available":"true","data":{"value":"true"}}}]} )
self._postReq('menuitems/settings/update', {"values":[{"value":{"Nodeid":self._nodeId,"Controllable":"true","Available":"true","data":{"value":"true"}}}]} )
self._state = True

def turn_off(self, **kwargs):
self._postReq('menuitems/settings/update', {"values":[{"value":{"Nodeid":2131230774,"Controllable":"true","Available":"true","data":{"value":"false"}}}]} )
self._postReq('menuitems/settings/update', {"values":[{"value":{"Nodeid":self._nodeId,"Controllable":"true","Available":"true","data":{"value":"false"}}}]} )
self._state = False

def getState(self):
fullstate = self._postReq('menuitems/settings/current', {'nodes':[{'nodeid':2131230774}]})
fullstate = self._postReq('menuitems/settings/current', {'nodes':[{'nodeid':self._nodeId}]})
if fullstate:
self._available = True
ahstat = fullstate['values'][0]['value']['data']['value']
Expand Down