homebridge-kasa-python
Version:
Plugin that uses Python-Kasa API to communicate with Kasa Devices.
48 lines • 1.96 kB
JavaScript
import HomeKitDeviceLightBulb from './homekitLightBulb.js';
import HomeKitDevicePlug from './homekitPlug.js';
import HomeKitDevicePowerStrip from './homekitPowerStrip.js';
import HomeKitDeviceSwitch from './homekitSwitch.js';
import HomeKitDeviceSwitchWithChildren from './homekitSwitchWithChildren.js';
import { LightBulbs, Plugs, PowerStrips, Switches } from './kasaDevices.js';
function isLightBulb(device) {
return LightBulbs.includes(device.sys_info.model);
}
function isPlug(device) {
return Plugs.includes(device.sys_info.model);
}
function isPowerStrip(device) {
return PowerStrips.includes(device.sys_info.model);
}
function isSwitch(device) {
return Switches.includes(device.sys_info.model);
}
export default function create(platform, kasaDevice) {
if (isLightBulb(kasaDevice)) {
const lightBulb = kasaDevice;
platform.log.debug('HomeKit device is a LightBulb:', lightBulb.sys_info.model);
return new HomeKitDeviceLightBulb(platform, lightBulb);
}
if (isPlug(kasaDevice)) {
const plug = kasaDevice;
platform.log.debug('HomeKit device is a Plug:', plug.sys_info.model);
return new HomeKitDevicePlug(platform, plug);
}
if (isPowerStrip(kasaDevice)) {
const powerStrip = kasaDevice;
platform.log.debug('HomeKit device is a PowerStrip:', powerStrip.sys_info.model);
return new HomeKitDevicePowerStrip(platform, powerStrip);
}
if (isSwitch(kasaDevice)) {
const switchDevice = kasaDevice;
platform.log.debug('HomeKit device is a Switch:', switchDevice.sys_info.model);
if (switchDevice.sys_info.child_num > 0) {
return new HomeKitDeviceSwitchWithChildren(platform, switchDevice);
}
else {
return new HomeKitDeviceSwitch(platform, switchDevice);
}
}
platform.log.error('Unknown device type:', kasaDevice);
return undefined;
}
//# sourceMappingURL=create.js.map