Kasa (TP-Link) Support Added
The Edge-AI Home Monitoring System now supports TP-Link Kasa smart plugs/switches, using the python-kasa library’s async Discover API for device communication.
What’s New
- New
Kasaclass that discovers a device by IP viaDiscover.discover_single()(with optional username/password for cloud-authenticated devices) and wrapsturn_on/turn_off/execute_commandbehind the sameasyncio.run()pattern already used for Daikin and the Tapo devices. - New
/api/kasaendpoint, gated behind@auth.login_requiredlike the rest of the device APIs. - Registered
kasainDEVICE_ENDPOINTSand wired it intocreate_device_action, so Kasa devices can already be used as automation actions from day one. - Added
send_kasaandsend_daikinhelper functions alongside the other device senders, for consistency across the codebase.
Why This Matters
Kasa is one of the most common smart plug ecosystems out there, so this adds another affordable device family to the system without needing a proprietary hub — anything plugged into a Kasa switch can now be turned on/off from the dashboard or from an automation rule, the same way Tapo and Shelly devices already are.
Challenges
- Ran into a syntax issue in
async_connect:await self.device = Discover.discover_single(...)isn’t valid — assignment has to come first, i.e.self.device = await Discover.discover_single(...). Needs fixing before this can actually run. -
handle_kasacurrently points at a config path (/config/device_config.json) that doesn’t match the filename (devices_config.json) or the relative-path convention used by every other handler — needs to be corrected to"config/devices_config.json". - Same route also references
data["Room"][room][dev_type][number][ip]withipunquoted (a variable reference instead of the string key"ip"), which will throw aNameErrorrather than the intendedKeyError. -
emit_device_eventstill isn’t wired into the Kasa (or Shelly) handler, so — same as the other non-TV devices — Kasa state changes can’t yet act as automation triggers.
Next Steps
- Fix the
await/assignment order bug inKasa.async_connect, the config path, and the unquoted"ip"key in/api/kasabefore testing against a real device. - Wire
emit_device_eventinto Kasa, Shelly, and the remaining handlers so any device can act as both an action and a trigger. - Once event emission is consistent across all device types, move on to energy monitoring for the Tapo smart plugs.
Comments 0
No comments yet. Be the first!
Sign in to join the conversation.