homebridge-airthings icon indicating copy to clipboard operation
homebridge-airthings copied to clipboard

Convert Plugin from Homebridge Accessory to Platform Plugin

Open Copilot opened this issue 4 months ago • 1 comments

This PR converts the homebridge-airthings plugin from an accessory plugin to a platform plugin, enabling better scalability and management of multiple Airthings devices from a single configuration.

Key Changes

Architecture Migration

  • Platform Implementation: Created AirthingsPlatform class implementing DynamicPlatformPlugin
  • Accessory Conversion: Converted existing AirthingsPlugin to AirthingsPlatformAccessory
  • Module Registration: Updated registration from api.registerAccessory() to api.registerPlatform()

Configuration Structure

Before (Accessory):

"accessories": [
  {
    "accessory": "Airthings",
    "name": "Living Room Monitor",
    "clientId": "...",
    "clientSecret": "...",
    "serialNumber": "2960123456"
  }
]

After (Platform):

"platforms": [
  {
    "platform": "Airthings",
    "clientId": "...",
    "clientSecret": "...",
    "devices": [
      {
        "name": "Living Room Monitor",
        "serialNumber": "2960123456"
      },
      {
        "name": "Bedroom Monitor", 
        "serialNumber": "2920654321"
      }
    ]
  }
]

Benefits

  • Multi-device Support: Manage multiple Airthings devices from single platform configuration
  • Shared Authentication: Single clientId/clientSecret pair for all devices
  • Dynamic Discovery: Platform can dynamically register/unregister accessories
  • Better Resource Management: Shared API client and rate limiting across devices
  • Homebridge UI: Updated config schema for improved user experience

Preserved Functionality

  • All existing sensor support (air quality, temperature, humidity, CO2, pressure, radon)
  • All configuration options (sensor disabling, thresholds, refresh intervals)
  • Battery service support
  • Air quality calculations and thresholds
  • Debug logging capabilities

Migration Required

Users will need to update their configuration from the accessory format to the platform format. The Homebridge UI will guide users through this change with the updated schema.

Fixes #65.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Jul 04 '25 18:07 Copilot

@coploit merge

pizzapi2012 avatar Sep 15 '25 15:09 pizzapi2012