Skip to content

Commit

Permalink
v4.0.5-test.4
Browse files Browse the repository at this point in the history
  • Loading branch information
seydx committed Apr 30, 2021
1 parent 2323700 commit c3e0137
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 33 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "homebridge-camera-ui",
"version": "4.0.5-test.3",
"version": "4.0.5-test.4",
"description": "User Interface for RTSP capable cameras.",
"author": "SeydX (https://github.com/SeydX/homebridge-camera-ui)",
"scripts": {
Expand Down
9 changes: 4 additions & 5 deletions plugin/accessories/doorbell.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class doorbellService {
constructor(api, accessory, handler) {
this.api = api;
this.accessory = accessory;

this.handler = handler;

this.getService();
Expand All @@ -23,7 +22,7 @@ class doorbellService {

if (this.accessory.context.config.doorbell) {
if (!service) {
logger.info('Adding doorbell', this.accessory.displayName);
logger.info('Adding doorbell service', this.accessory.displayName);
service = this.accessory.addService(
this.api.hap.Service.Doorbell,
this.accessory.displayName + ' Doorbell',
Expand All @@ -32,14 +31,14 @@ class doorbellService {
}
} else {
if (service) {
logger.info('Removing doorbell', this.accessory.displayName);
logger.info('Removing doorbell service', this.accessory.displayName);
this.accessory.removeService(service);
}
}

if (this.accessory.context.config.switches) {
if (!switchService) {
logger.info('Adding doorbell switch', this.accessory.displayName);
logger.info('Adding switch service (doorbell)', this.accessory.displayName);
switchService = this.accessory.addService(
this.api.hap.Service.Switch,
this.accessory.displayName + ' Doorbell Trigger',
Expand All @@ -53,7 +52,7 @@ class doorbellService {
});
} else {
if (switchService) {
logger.info('Removing doorbell switch', this.accessory.displayName);
logger.info('Removing switch service (doorbell)', this.accessory.displayName);
this.accessory.removeService(switchService);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
'use strict';

const logger = require('../../services/logger/logger.service');
const SettingsModel = require('../../server/components/settings/settings.model');
const logger = require('homebridge-camera-ui/services/logger/logger.service');
const SettingsModel = require('homebridge-camera-ui/server/components/settings/settings.model');

const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();

class SwitchAccessory {
constructor(api, accessory, subtype, name, removeSwitch) {
constructor(api, accessory, subtype, type) {
this.api = api;
this.accessory = accessory;

this.name = name ? `${accessory.displayName} ${name}` : accessory.displayName;
this.type = type;
this.subtype = subtype;

if (removeSwitch) {
this.getService();
} else {
this.removeService();
}
this.subname = `${capitalize(subtype.split('-')[0])} ${capitalize(subtype.split('-')[1])}`;
this.name = type === 'accessory' ? accessory.displayName : `${accessory.displayName} ${this.subname}`;
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
Expand All @@ -26,7 +25,7 @@ class SwitchAccessory {
let service = this.accessory.getServiceById(this.api.hap.Service.Switch, this.subtype);

if (!service) {
logger.info('Adding Switch service', this.name);
logger.info(`Adding Switch service (${this.subtype})`, this.accessory.displayName);
service = this.accessory.addService(this.api.hap.Service.Switch, this.name, this.subtype);
}

Expand Down Expand Up @@ -63,7 +62,7 @@ class SwitchAccessory {
removeService() {
let service = this.accessory.getServiceById(this.api.hap.Service.Switch, this.subtype);
if (service) {
logger.info('Removing switch service', this.name);
logger.info(`Removing switch service (${this.subtype})`, this.accessory.displayName);
this.accessory.removeService(service);
}
}
Expand Down Expand Up @@ -115,7 +114,7 @@ class SwitchAccessory {
if (state && !exclude.includes(this.accessory.displayName)) {
exclude.push(this.accessory.displayName);
} else if (!state && exclude.includes(this.accessory.displayName)) {
exclude = exclude.filter((cam) => cam && cam.name !== this.accessory.displayName);
exclude = exclude.filter((cameraName) => cameraName && cameraName !== this.accessory.displayName);
}

await SettingsModel.patchByTarget('general', {
Expand Down
9 changes: 4 additions & 5 deletions plugin/accessories/motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class motionService {
constructor(api, accessory, handler) {
this.api = api;
this.accessory = accessory;

this.handler = handler;

this.getService();
Expand All @@ -23,7 +22,7 @@ class motionService {

if (this.accessory.context.config.motion) {
if (!service) {
logger.info('Adding motion sensor', this.accessory.displayName);
logger.info('Adding motion sensor service', this.accessory.displayName);
service = this.accessory.addService(
this.api.hap.Service.MotionSensor,
this.accessory.displayName + ' Motion',
Expand All @@ -37,14 +36,14 @@ class motionService {
});
} else {
if (service) {
logger.info('Removing motion sensor', this.accessory.displayName);
logger.info('Removing motion sensor service', this.accessory.displayName);
this.accessory.removeService(service);
}
}

if (this.accessory.context.config.switches) {
if (!switchService) {
logger.info('Adding motion switch', this.accessory.displayName);
logger.info('Adding switch service (motion)', this.accessory.displayName);
switchService = this.accessory.addService(
this.api.hap.Service.Switch,
this.accessory.displayName + ' Motion Trigger',
Expand All @@ -58,7 +57,7 @@ class motionService {
});
} else {
if (switchService) {
logger.info('Removing motion switch', this.accessory.displayName);
logger.info('Removing switch service (motion)', this.accessory.displayName);
this.accessory.removeService(switchService);
}
}
Expand Down
13 changes: 6 additions & 7 deletions plugin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Camera = require('./accessories/camera');
const DoorbellSensor = require('./accessories/doorbell');
const MotionSensor = require('./accessories/motion');

const InterfaceAccessory = require('./accessories/interface');
const InterfaceSwitch = require('homebridge-camera-ui/plugin/accessories/interface-switch');

const Server = require('../server/index');
const Config = require('../services/config/config.start');
Expand All @@ -21,7 +21,6 @@ var Accessory, UUIDGen;
module.exports = function (homebridge) {
Accessory = homebridge.platformAccessory;
UUIDGen = homebridge.hap.uuid;

return CameraUI;
};

Expand Down Expand Up @@ -146,19 +145,19 @@ CameraUI.prototype = {
if (device.subtype.includes('camera')) {
new MotionSensor(this.api, accessory);
new DoorbellSensor(this.api, accessory);
const interfaceSwitches = new InterfaceSwitch(this.api, accessory, 'exclude-switch', 'service');

if (device.excludeSwitch) {
const removeSwitch = false;
new InterfaceAccessory(this.api, accessory, 'exclude-switch', 'Exclude Switch', removeSwitch);
interfaceSwitches.getService();
} else {
const removeSwitch = true;
new InterfaceAccessory(this.api, accessory, 'exclude-switch', 'Exclude Switch', removeSwitch);
interfaceSwitches.removeService();
}

const cameraAccessory = new Camera(this.api, accessory, this.config.options.videoProcessor);
accessory.configureController(cameraAccessory.controller);
} else if (device.subtype.includes('switch')) {
new InterfaceAccessory(this.api, accessory, device.subtype);
const interfaceSwitches = new InterfaceSwitch(this.api, accessory, device.subtype, 'accessory');
interfaceSwitches.getService();
}
},

Expand Down
2 changes: 1 addition & 1 deletion services/config/config.start.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ConfigSetup {
port: config.plugin.port || 8181,
language: config.plugin.language || 'auto',
theme: config.plugin.theme || 'auto',
atHome: config.plugin.atHome || false,
atHomeSwitch: config.plugin.atHomeSwitch || false,
};

return ui;
Expand Down

0 comments on commit c3e0137

Please sign in to comment.