@mleiber, I have updated the KEF integration, see this PR
It works locally for me.
The only thing I am unsure about is whether the play, pause and next prev track are supported when playing over USB. I guess it’s not. Now I have implemented it such that the controls are only available when the source is either Bluetooth or Wifi.
Wow, that was quick . Re USB, don’t know either, I didn’t think about the source at all, just tried it with Wifi here. I will hook up my Macbook in the next days and check if it does any good to the USB source. I will use my ‘testbed’ as you wrote you already restricted the implementation to BT and Wifi/LAN.
I will continue make an attempt to figure out a way to detect the play/idle state of the player - I have some automations in mind where it would be handy to know the state and get triggers based on the state.
@basnijholt, I have temporarily copied your changes into a custom component and tested it - works nicely. Now only if one could figure out what the play state is so that e.g. the button in the media player UI shows the right thing!
For those with the old hardware version that can’t be turned on via the App i.e. models where WiFi goes off when the unit is off, if you don’t want to see the “Unavailable” state in the UI and prefer On / Off, this can be done by tweaking media_player.py in this custom component.
modded in various places
import subprocess
....
#in the KEFMediaPlayer class:
# inside the init constructor
...
"""Initialize the media player."""
...
self._host = host
def pingDevice(self):
"""ping DEVICE - AR MOD"""
cmd = ['ping', '-c1', '-W2', self._host ]
response = subprocess.Popen(cmd, stdout=subprocess.PIPE)
stdout, stderr = response.communicate()
if response.returncode == 0:
return True
else:
return False
@property
def state(self):
"""Return the state of the device."""
if not self.pingDevice():
self._state = STATE_OFF
return self._state
@property
def available(self):
"""Return if the speaker is reachable online."""
# avoid 'unavailable' by returnining TRUE
# and also set the state based on ping
if not self.pingDevice():
self._state = STATE_OFF
return True
@basnijholt that would be much better than my quick hack
Note that to get this to behave in the expected way, you will need to tweak the available() method based on ping response, and you want to do this only for the old hardware (e.g. for people that disable the on/off control) that is not “always connected”. For the new hardware, your current logic makes sense.
I seem to have lost my integration with the upgrade to 108. Anyone else?
2020-04-08 13:10:42 ERROR (MainThread) [homeassistant.components.media_player] Error while setting up kef platform for media_player
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
await asyncio.gather(*pending)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities
await asyncio.gather(*tasks)
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 445, in _async_add_entity
await entity.async_added_to_hass()
File "/usr/src/homeassistant/homeassistant/components/kef/media_player.py", line 381, in async_added_to_hass
self.hass, self.update_dsp, DSP_SCAN_INTERVAL
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 293, in async_track_time_interval
remove = async_track_point_in_utc_time(hass, interval_listener, next_interval())
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 284, in next_interval
return dt_util.utcnow() + interval
TypeError: unsupported operand type(s) for +: 'datetime.datetime' and 'int'
Not sure since when it happened, guess it came with the update to 0.108. I now see this frequently in the logs and given the function update_dsp() is mentioned it might have to do with the new feature to configure the KEF LS50 Wireless DSP.
async_track_point_in_utc_time.<locals>.point_in_time_listener(<Event time_c....008180+02:00>) at /usr/src/homeassistant/homeassistant/helpers/event.py:234
Traceback (most recent call last):
File "/usr/local/lib/python3.7/asyncio/events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 250, in point_in_time_listener
hass.async_run_job(action, now)
File "/usr/src/homeassistant/homeassistant/core.py", line 374, in async_run_job
target(*args)
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 291, in interval_listener
hass.async_run_job(action, now)
File "/usr/src/homeassistant/homeassistant/core.py", line 376, in async_run_job
self.async_add_job(target, *args)
File "/usr/src/homeassistant/homeassistant/core.py", line 308, in async_add_job
task = self.loop.create_task(target(*args))
TypeError: update_dsp() takes 1 positional argument but 2 were given
@basnijholt thanks for this great integration. Using it daily in my home office
I was hoping the new Equalizer settings would be exposed in the Media Player details page. It seems you have to crate your own “expandable” card with this for now. Any chance this can be added to the Media Player card as well?
I have a pair of KEF LSX, but I seem to need to power cycle my speakers to get them back once they become Unavailable. When they show up as Unavailable in Home Assistant, they are also not accessible via KEF Control. I do still however have the ability to stream to them using Spotify Connect, and control volume (through Spotify), and the physical remote control works. I also have access to their basic interface on port 80, where you can change some WIFI settings etc. It’s only the control interface that has crashed.
I raised this ticket:
I seem to have another issue with my KEF LSX, which is that they don’t remember the mode/DSP settings after wake-up from stand-by. They are back at default. If I send the “correct” DSP settings, settings which the speakers think they should already have, then they are still not applied. I have to change to a different DSP value, and then back to the desired value.
Both of these issues I have raised with KEF support, but so far they haven’t been very helpful.
My speakers are running firmware p20.4101909240.105243422.