GithubHelp home page GithubHelp logo

basnijholt / aiokef Goto Github PK

View Code? Open in Web Editor NEW
37.0 37.0 6.0 229 KB

Asyncio Python API for KEF speakers 🔈

License: MIT License

Python 91.22% Jupyter Notebook 8.78%
home-assistant kef kef-speakers ls50 ls50w lsx python

aiokef's Introduction

Bas Nijholt 👋

  • 👷🏻‍♂️ Currently at IonQ, doing my bit in building a quantum computer, before that I was at Microsoft Quantum.
  • 🌟 A deep dive into computational topological quantum mechanics earned me my PhD.
  • 🎨 I've crafted a few libraries for Home Assistant, making home automation a bit more fun.
  • ⚒️ Made other tools speed up and massively parallelize numerical simulations.
  • 🏅 Very passionate about open-source, software quality, user experience, and smooth performance.
  • 🐍 Python is my go-to language in most of my projects.
  • Some of my favorite creations:
    • 📈 python-adaptive/adaptive: Parallel active learning of mathematical functions? Check!
    • 🧬 unidep: Unifying pip and conda requirements, single command to set up a full dev environment.
    • 💡 adaptive-lighting: A custom component for Home Assistant to keep your lighting in synn with the sun.
    • 📝 markdown-code-runner: Run (hidden) code blocks right within your Markdown files - keep simple README.mds in sync!
    • 🕒 rsync-time-machine.py: Time Machine-style backups with rsync for the minimalists.
    • 🏠 home-assistant-config: Over 100 documented automations in my Home Assistant config

Below are some (automatically generated) statistics about my activity on GitHub. For more info check out my website www.nijho.lt or talk to me on Mastodon.

Ask me about:

Last updated at 2024-04-30 12:10:31.008276.

GitHub statistics — my top 20

number of GitHub stars ⭐️

  1. basnijholt/home-assistant-config, 1645 ⭐️s
  2. basnijholt/adaptive-lighting, 1608 ⭐️s
  3. python-adaptive/adaptive, 1113 ⭐️s
  4. python-kasa/python-kasa, 1094 ⭐️s
  5. basnijholt/lovelace-ios-themes, 563 ⭐️s
Click to expand!
  1. basnijholt/lovelace-ios-dark-mode-theme, 441 ⭐️s
  2. basnijholt/rsync-time-machine.py, 366 ⭐️s
  3. basnijholt/miflora, 360 ⭐️s
  4. topocm/topocm_content, 267 ⭐️s
  5. basnijholt/home-assistant-streamdeck-yaml, 206 ⭐️s
  6. basnijholt/unidep, 205 ⭐️s
  7. basnijholt/home-assistant-macbook-touch-bar, 95 ⭐️s
  8. kwant-project/kwant, 84 ⭐️s
  9. basnijholt/markdown-code-runner, 81 ⭐️s
  10. basnijholt/home-assistant-streamdeck-yaml-addon, 62 ⭐️s
  11. basnijholt/aiokef, 37 ⭐️s
  12. basnijholt/thesis-cover, 34 ⭐️s
  13. basnijholt/adaptive-scheduler, 26 ⭐️s
  14. basnijholt/instacron, 20 ⭐️s
  15. kwant-project/kwant-tutorial-2016, 19 ⭐️s

number of commits :octocat:

  1. python-adaptive/adaptive, 1427 commits :octocat:
  2. basnijholt/adaptive-scheduler, 755 commits :octocat:
  3. basnijholt/thesis, 452 commits :octocat:
  4. basnijholt/supercurrent-majorana-nanowire, 282 commits :octocat:
  5. conda-forge/staged-recipes, 279 commits :octocat:
Click to expand!
  1. basnijholt/net-worth-tracker, 228 commits :octocat:
  2. python-adaptive/paper, 198 commits :octocat:
  3. home-assistant/core, 192 commits :octocat:
  4. basnijholt/spin-orbit-nanowires, 191 commits :octocat:
  5. ohld/igbot, 191 commits :octocat:
  6. basnijholt/instacron, 115 commits :octocat:
  7. microsoft/Qcodes, 109 commits :octocat:
  8. basnijholt/yaml2bib, 91 commits :octocat:
  9. basnijholt/home-assistant-streamdeck-yaml-addon, 80 commits :octocat:
  10. basnijholt/home-assistant-macbook-touch-bar, 69 commits :octocat:
  11. conda-forge/kwant-feedstock, 65 commits :octocat:
  12. basnijholt/miflora, 57 commits :octocat:
  13. AppDaemon/appdaemon, 52 commits :octocat:
  14. conda-forge/hpc05-feedstock, 49 commits :octocat:
  15. basnijholt/conda-recipes, 48 commits :octocat:

These plots and stats are generated by this Jupyter notebook using this GitHub Action.

aiokef's People

Contributors

basnijholt avatar dge8 avatar github-actions[bot] avatar gronis avatar onkelbeh avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

aiokef's Issues

Feature request: speaker discovery

Hi all, submitting a feature request for discovery of Kef speakers on the LAN using mDNS. I may be able to put together a PoC for this soon myself.

Objective would be to specify a speaker by serial number or MAC address and have Avahi/mDNS resolve that into an IP address, or to produce a list of all speakers (with model, serials, etc.) currently on the LAN. There's quite a bit of info advertised in the mDNS packet itself.

This could form a separate submodule "discovery" or similar to minimise required Python modules for those that don't need this functionality.

Thanks and regards,
Dan.

KEF LSX becomes unresponsive / Unavailable

Love this integration, but I am having a bit of an issue with my KEF LSX. It's very sporadic and I haven't found a clear pattern.

My speakers sporadically end up as Unavailable in Home Assistant, and when this happens they also stop responding to the KEF Control app on my Android phone. They are still responding on port 80, for the simple web interface, so their WiFi connectivity is still solid (signal strength showing "excellent").

Firmware: p20.4101909240.105243422

This is likely an issue with robustness on the speaker side, but perhaps it's also possible to make the aiokef integration a bit kinder to avoid the problem.

Possibly similar to what kraih describes having issues with kefctl:
kraih/kefctl#1

I have an Automation which sets a bunch of DSP settings (for some reason my LSX speakers don't save these during Standby) when the speakers start up, and then my understanding is that the aiokef integration will check the DSP settings once per hour.

KEF LSX in Logbook from 09:00 to 20:00
6 October 2020
19:08:53
KEF LSX changed to unavailable
19:05:18
KEF LSX turned on
18:17:48
KEF LSX turned off
16:11:47
KEF LSX turned on
16:03:17
KEF LSX turned off
11:35:22
KEF LSX turned on by User

There are many traces for "Opening connection", "Opening connection successful", and "Opening connection failed"

The triggering event for my Automation to switch on the LSX speakers to Aux input is logged at 19:04:49.

Here is the first sign of an error, followed by continuous failures to connect:


2020-10-06 19:08:45 DEBUG (MainThread) [aiokef.aiokef] 10.0.1.36: Writing message: b"G'\x80"
2020-10-06 19:08:45 ERROR (MainThread) [aiokef.aiokef] 10.0.1.36: Got an exception in writing
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiokef/aiokef.py", line 299, in _send_message
    await self._writer.drain()
  File "/usr/local/lib/python3.8/asyncio/streams.py", line 375, in drain
    raise exc
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 846, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer
2020-10-06 19:08:45 DEBUG (MainThread) [aiokef.aiokef] 10.0.1.36: _disconnect called
2020-10-06 19:08:45 DEBUG (MainThread) [aiokef.aiokef] 10.0.1.36: Cancelling the _disconnect_task
2020-10-06 19:08:45 DEBUG (MainThread) [aiokef.aiokef] 10.0.1.36: Going to disconnect now
2020-10-06 19:08:45 ERROR (MainThread) [aiokef.aiokef] 10.0.1.36: Disconnecting raised
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiokef/aiokef.py", line 327, in _disconnect
    await self._writer.wait_closed()
  File "/usr/local/lib/python3.8/asyncio/streams.py", line 359, in wait_closed
    await self._protocol._get_close_waiter(self)
  File "/usr/local/lib/python3.8/site-packages/aiokef/aiokef.py", line 299, in _send_message
    await self._writer.drain()
  File "/usr/local/lib/python3.8/asyncio/streams.py", line 375, in drain
    raise exc
  File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 846, in _read_ready__data_received
    data = self._sock.recv(self.max_size)
ConnectionResetError: [Errno 104] Connection reset by peer

Separation of concerns: speaker and protocol

Hi all, thanks for your work on this project, it's been really useful!

I'm working on a project that runs on a Raspberry Pi and allows controlling Kef speakers via HDMI CEC control, basically emulating HDMI ARC on sound bars (and in the newer LS50W IIs and LS60s). Speakers turn on with the TV, changing TV volume changes speaker volume, turn off again when the TV turns off, etc. The actual audio path is of course still via optical.

I would like to use the Kef protocol in this library in a more direct way - without the tenacity retry module, or volume scale, or helpers for splitting e.g. volume and mute. I'd rather implement that stuff higher up in my own project.

Would you be open to separating the module into a submodule focussed entirely on modelling the protocol ("proto"), and another submodule focussed on abstracting the speaker functions ("speaker")? I've submitted another issue covering a third possible submodule "discovery".

I'd be happy to attempt this in a branch and bring it for review although I will only be able to test on my LSX.

Thanks and regards,
Dan.

Kef LSX

Kef LSX uses some different inputs which leads to a fail.
i.e. Wifi returns the status 2.
I will test the status codes for the LSX tomorrow.

20 minutes standby bug

When turning off the KEF speakers with a 20 minutes standby, the speakers become "Unavailable".

It doesn't seem related to this code, the same happens when using the app.

It does work fine with no standby or 60 minutes.

AttributeError: 'str' object has no attribute '_asdict'

2020-09-06 10:02:38 ERROR (MainThread) [homeassistant.components.media_player] kef_custom: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 335, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 454, in async_device_update
    await self.async_update()  # type: ignore
  File "/config/custom_components/kef_custom/media_player.py", line 250, in async_update
    await self.update_dsp()
  File "/config/custom_components/kef_custom/media_player.py", line 382, in update_dsp
    self._dsp = dict(zip(keys, rest), **mode._asdict())
AttributeError: 'str' object has no attribute '_asdict'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.