本帖最后由 mitu 于 2018-4-16 19:28 编辑
今天几位大神用porxy和light_template将Homeassistant中的开关改成灯泡形式用于在Homekit中将开关显示为灯泡,其实完全可以修改Homebridge-Homeassistant插件中switch.js文件来实现,只需将原来文件中第154行-165行修改即可:原文件:
this.service = new Service.Switch();
if (this.data && this.data.attributes && this.data.attributes.homebridge_switch_type === 'outlet') {
this.service = new Service.Outlet();
if (this.data.attributes && this.data.attributes.homebridge_model) {
model = String(this.data.attributes.homebridge_model);
} else {
model = 'Outlet';
}
this.service
.getCharacteristic(Characteristic.OutletInUse)
.on('get', this.getPowerState.bind(this));
}
改为:
this.service = new Service.Switch();
if (this.data && this.data.attributes && (this.data.attributes.homebridge_switch_type === 'lock' || this.data.attributes.homebridge_switch_type === 'fan' || this.data.attributes.homebridge_switch_type === 'outlet' || this.data.attributes.homebridge_switch_type === 'light')) {
if (this.data.attributes.homebridge_switch_type === 'outlet') {
this.service = new Service.Outlet();
model = 'Outlet';
this.service
.getCharacteristic(Characteristic.OutletInUse)
.on('get', this.getPowerState.bind(this));
} else if (this.data.attributes.homebridge_switch_type === 'light') {
this.service = new Service.Lightbulb();
model = 'Light';
} else if (this.data.attributes.homebridge_switch_type === 'fan') {
this.service = new Service.Fan();
model = 'Fan';
} else if (this.data.attributes.homebridge_switch_type === 'lock') {
this.service = new Service.LockMechanism();
model = 'Lock';
}
if (this.data.attributes && this.data.attributes.homebridge_model) {
model = String(this.data.attributes.homebridge_model);
}
}
修改好的文件可以直接放到原来的位置即可。
我用的是ubuntu,文件路径:/usr/lib/node_modules/homebridge-homeassistant/accessories
|