Philips js state (#21407)
* Switch to SCAN_INTERVAL instead of throttle This allows forced update of state * Don't change tv on/off state in services * Drop unused variables * Only send mute if different from current state * No need to update variables, will behandled on update * Drop unused importpull/21416/head
parent
a4bb35142c
commit
814e610b1d
|
@ -19,13 +19,12 @@ from homeassistant.const import (
|
||||||
CONF_API_VERSION, CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON)
|
CONF_API_VERSION, CONF_HOST, CONF_NAME, STATE_OFF, STATE_ON)
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.script import Script
|
from homeassistant.helpers.script import Script
|
||||||
from homeassistant.util import Throttle
|
|
||||||
|
|
||||||
REQUIREMENTS = ['ha-philipsjs==0.0.5']
|
REQUIREMENTS = ['ha-philipsjs==0.0.5']
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
SCAN_INTERVAL = timedelta(seconds=30)
|
||||||
|
|
||||||
SUPPORT_PHILIPS_JS = SUPPORT_TURN_OFF | SUPPORT_VOLUME_STEP | \
|
SUPPORT_PHILIPS_JS = SUPPORT_TURN_OFF | SUPPORT_VOLUME_STEP | \
|
||||||
SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \
|
||||||
|
@ -72,8 +71,6 @@ class PhilipsTV(MediaPlayerDevice):
|
||||||
self._tv = tv
|
self._tv = tv
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = None
|
self._state = None
|
||||||
self._min_volume = None
|
|
||||||
self._max_volume = None
|
|
||||||
self._volume = None
|
self._volume = None
|
||||||
self._muted = False
|
self._muted = False
|
||||||
self._program_name = None
|
self._program_name = None
|
||||||
|
@ -123,10 +120,6 @@ class PhilipsTV(MediaPlayerDevice):
|
||||||
"""Set the input source."""
|
"""Set the input source."""
|
||||||
if source in self._source_mapping:
|
if source in self._source_mapping:
|
||||||
self._tv.setSource(self._source_mapping.get(source))
|
self._tv.setSource(self._source_mapping.get(source))
|
||||||
self._source = source
|
|
||||||
if not self._tv.on:
|
|
||||||
self._state = STATE_OFF
|
|
||||||
self._watching_tv = bool(self._tv.source_id == 'tv')
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def volume_level(self):
|
def volume_level(self):
|
||||||
|
@ -146,26 +139,20 @@ class PhilipsTV(MediaPlayerDevice):
|
||||||
def turn_off(self):
|
def turn_off(self):
|
||||||
"""Turn off the device."""
|
"""Turn off the device."""
|
||||||
self._tv.sendKey('Standby')
|
self._tv.sendKey('Standby')
|
||||||
if not self._tv.on:
|
|
||||||
self._state = STATE_OFF
|
|
||||||
|
|
||||||
def volume_up(self):
|
def volume_up(self):
|
||||||
"""Send volume up command."""
|
"""Send volume up command."""
|
||||||
self._tv.sendKey('VolumeUp')
|
self._tv.sendKey('VolumeUp')
|
||||||
if not self._tv.on:
|
|
||||||
self._state = STATE_OFF
|
|
||||||
|
|
||||||
def volume_down(self):
|
def volume_down(self):
|
||||||
"""Send volume down command."""
|
"""Send volume down command."""
|
||||||
self._tv.sendKey('VolumeDown')
|
self._tv.sendKey('VolumeDown')
|
||||||
if not self._tv.on:
|
|
||||||
self._state = STATE_OFF
|
|
||||||
|
|
||||||
def mute_volume(self, mute):
|
def mute_volume(self, mute):
|
||||||
"""Send mute command."""
|
"""Send mute command."""
|
||||||
self._tv.sendKey('Mute')
|
if self._muted != mute:
|
||||||
if not self._tv.on:
|
self._tv.sendKey('Mute')
|
||||||
self._state = STATE_OFF
|
self._muted = mute
|
||||||
|
|
||||||
def set_volume_level(self, volume):
|
def set_volume_level(self, volume):
|
||||||
"""Set volume level, range 0..1."""
|
"""Set volume level, range 0..1."""
|
||||||
|
@ -186,12 +173,9 @@ class PhilipsTV(MediaPlayerDevice):
|
||||||
return '{} - {}'.format(self._source, self._channel_name)
|
return '{} - {}'.format(self._source, self._channel_name)
|
||||||
return self._source
|
return self._source
|
||||||
|
|
||||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data and update device state."""
|
"""Get the latest data and update device state."""
|
||||||
self._tv.update()
|
self._tv.update()
|
||||||
self._min_volume = self._tv.min_volume
|
|
||||||
self._max_volume = self._tv.max_volume
|
|
||||||
self._volume = self._tv.volume
|
self._volume = self._tv.volume
|
||||||
self._muted = self._tv.muted
|
self._muted = self._tv.muted
|
||||||
if self._tv.source_id:
|
if self._tv.source_id:
|
||||||
|
|
Loading…
Reference in New Issue