Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
0846a72931 | |||
f1d1da0945 | |||
76438d6811 | |||
7971fd3ec1 | |||
3fe902c50b | |||
52a259dafd | |||
128bb933bd |
59
.drone.yml
59
.drone.yml
@ -5,6 +5,9 @@ name: default
|
|||||||
clone:
|
clone:
|
||||||
disable: true
|
disable: true
|
||||||
|
|
||||||
|
node:
|
||||||
|
lan: internal
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: clone
|
- name: clone
|
||||||
image: alpine/git
|
image: alpine/git
|
||||||
@ -66,6 +69,62 @@ steps:
|
|||||||
exclude:
|
exclude:
|
||||||
- pull_request
|
- pull_request
|
||||||
|
|
||||||
|
- name: remove old package
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
environment:
|
||||||
|
SSH_USER:
|
||||||
|
from_secret: ssh_user
|
||||||
|
settings:
|
||||||
|
host: homebridge.me
|
||||||
|
envs:
|
||||||
|
- SSH_USER
|
||||||
|
username:
|
||||||
|
from_secret: ssh_user
|
||||||
|
key:
|
||||||
|
from_secret: ssh_key
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- rm -r /home/$SSH_USER/.npm-global/lib/node_modules/@watsonb8/homebridge-harmony-control
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
- name: deploy
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: homebridge.me
|
||||||
|
username:
|
||||||
|
from_secret: ssh_user
|
||||||
|
key:
|
||||||
|
from_secret: ssh_key
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- npm install -g @watsonb8/homebridge-harmony-control --registry http://10.44.1.6:4873
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
|
- name: restart homebridge
|
||||||
|
image: appleboy/drone-ssh
|
||||||
|
settings:
|
||||||
|
host: homebridge.me
|
||||||
|
username:
|
||||||
|
from_secret: elevated_ssh_user
|
||||||
|
key:
|
||||||
|
from_secret: ssh_key
|
||||||
|
port: 22
|
||||||
|
script:
|
||||||
|
- systemctl restart homebridge
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
exclude:
|
||||||
|
- pull_request
|
||||||
|
|
||||||
- name: Notify
|
- name: Notify
|
||||||
image: drillster/drone-email
|
image: drillster/drone-email
|
||||||
settings:
|
settings:
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@watsonb8/homebridge-harmony-control",
|
"name": "@watsonb8/homebridge-harmony-control",
|
||||||
"version": "1.2.0",
|
"version": "1.2.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@watsonb8/homebridge-harmony-control",
|
"name": "@watsonb8/homebridge-harmony-control",
|
||||||
"version": "1.2.0",
|
"version": "1.2.3",
|
||||||
"description": "Homebridge platform to control smart home equipment by room.",
|
"description": "Homebridge platform to control smart home equipment by room.",
|
||||||
"main": "bin/index.js",
|
"main": "bin/index.js",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
|
@ -137,7 +137,10 @@ export class ControlUnit {
|
|||||||
break;
|
break;
|
||||||
//Turn on with first activity
|
//Turn on with first activity
|
||||||
case 1:
|
case 1:
|
||||||
this._activityService.startActivity(
|
if (this._activityService.getIsActive(this._accessory.displayName)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this._activityService.startLastOrDefaultActivity(
|
||||||
this._accessory.displayName,
|
this._accessory.displayName,
|
||||||
this._activities[0]
|
this._activities[0]
|
||||||
);
|
);
|
||||||
@ -150,7 +153,8 @@ export class ControlUnit {
|
|||||||
*/
|
*/
|
||||||
private onGetAccessoryActive = async () => {
|
private onGetAccessoryActive = async () => {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
return this._activityService.getIsActive(this._accessory.displayName)
|
return this._activityService.getCurrentActivity(this._accessory.displayName)
|
||||||
|
?.DisplayName
|
||||||
? this._platform.Characteristic.Active.ACTIVE
|
? this._platform.Characteristic.Active.ACTIVE
|
||||||
: this._platform.Characteristic.Active.INACTIVE;
|
: this._platform.Characteristic.Active.INACTIVE;
|
||||||
};
|
};
|
||||||
@ -176,7 +180,7 @@ export class ControlUnit {
|
|||||||
* Event handler for GET active identifier characteristic
|
* Event handler for GET active identifier characteristic
|
||||||
*/
|
*/
|
||||||
private onGetActiveIdentifier = async () => {
|
private onGetActiveIdentifier = async () => {
|
||||||
let currentActivity: IActivity = this._activityService.getIsActive(
|
let currentActivity: IActivity = this._activityService.getCurrentActivity(
|
||||||
this._accessory.displayName
|
this._accessory.displayName
|
||||||
)!;
|
)!;
|
||||||
let identifier: number = 0;
|
let identifier: number = 0;
|
||||||
|
@ -9,18 +9,30 @@ export class StateDataProvider {
|
|||||||
} = {};
|
} = {};
|
||||||
|
|
||||||
public updateState(activity: IActivity, controlUnitName: string): void {
|
public updateState(activity: IActivity, controlUnitName: string): void {
|
||||||
this._states[controlUnitName] = { currentActivity: activity };
|
const oldState = this._states[controlUnitName];
|
||||||
|
this._states[controlUnitName] = {
|
||||||
|
currentActivity: activity,
|
||||||
|
lastActivity: oldState?.lastActivity,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public deactivateState(controlUnitName: string): void {
|
||||||
|
const oldState = this._states[controlUnitName];
|
||||||
|
this._states[controlUnitName] = {
|
||||||
|
currentActivity: undefined,
|
||||||
|
lastActivity: oldState?.currentActivity,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public removeState(controlUnitName: string): void {
|
public removeState(controlUnitName: string): void {
|
||||||
this._states[controlUnitName] = undefined;
|
this._states[controlUnitName] = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getState(controlUnitName: string) {
|
public getState(controlUnitName: string): IActivityState | undefined {
|
||||||
if (!this._states[controlUnitName]) {
|
if (!this._states[controlUnitName]) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return this._states[controlUnitName]!.currentActivity;
|
return this._states[controlUnitName];
|
||||||
}
|
}
|
||||||
|
|
||||||
public get states(): {
|
public get states(): {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { IActivity } from "./config";
|
import { IActivity } from "./config";
|
||||||
|
|
||||||
export interface IActivityState {
|
export interface IActivityState {
|
||||||
currentActivity: IActivity;
|
currentActivity?: IActivity;
|
||||||
|
lastActivity?: IActivity;
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,18 @@ export class ActivityService {
|
|||||||
@inject("log") private _log: Logging
|
@inject("log") private _log: Logging
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
public startLastOrDefaultActivity = async (
|
||||||
|
controlUnitName: string,
|
||||||
|
defaultActivity: IActivity
|
||||||
|
) => {
|
||||||
|
const lastActivity = this.getLastActivity(controlUnitName);
|
||||||
|
if (!lastActivity) {
|
||||||
|
return this.startActivity(controlUnitName, defaultActivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.startActivity(controlUnitName, lastActivity);
|
||||||
|
};
|
||||||
|
|
||||||
public startActivity = async (
|
public startActivity = async (
|
||||||
controlUnitName: string,
|
controlUnitName: string,
|
||||||
activity: IActivity
|
activity: IActivity
|
||||||
@ -68,19 +80,24 @@ export class ActivityService {
|
|||||||
);
|
);
|
||||||
await this._harmonyDataProvider.powerOffDevices(devicesToTurnOff);
|
await this._harmonyDataProvider.powerOffDevices(devicesToTurnOff);
|
||||||
|
|
||||||
this._stateDataProvider.removeState(controlUnitName);
|
this._stateDataProvider.deactivateState(controlUnitName);
|
||||||
};
|
};
|
||||||
|
|
||||||
public getCurrentActivity(controlUnitName: string): IActivity | undefined {
|
public getCurrentActivity(controlUnitName: string): IActivity | undefined {
|
||||||
return this._stateDataProvider.getState(controlUnitName);
|
return this._stateDataProvider.getState(controlUnitName)?.currentActivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getLastActivity(controlUnitName: string): IActivity | undefined {
|
||||||
|
return this._stateDataProvider.getState(controlUnitName)?.lastActivity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return if a control unit is active
|
* Return if a control unit is active
|
||||||
* @param controlUnitName
|
* @param controlUnitName
|
||||||
*/
|
*/
|
||||||
public getIsActive(controlUnitName: string): IActivity | undefined {
|
public getIsActive(controlUnitName: string): boolean {
|
||||||
return this._stateDataProvider.getState(controlUnitName);
|
const state = this._stateDataProvider.getState(controlUnitName);
|
||||||
|
return state != undefined && state.currentActivity != undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -100,11 +117,11 @@ export class ActivityService {
|
|||||||
let currentOtherState: IActivityState =
|
let currentOtherState: IActivityState =
|
||||||
this._stateDataProvider.states[controlUnitKey]!;
|
this._stateDataProvider.states[controlUnitKey]!;
|
||||||
|
|
||||||
if (!currentOtherState) {
|
if (!currentOtherState || !currentOtherState.currentActivity) {
|
||||||
return devicesToTurnOn;
|
return devicesToTurnOn;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentOtherState.currentActivity.DeviceSetupList.forEach(
|
currentOtherState.currentActivity!.DeviceSetupList.forEach(
|
||||||
(value: IDeviceSetupItem) => {
|
(value: IDeviceSetupItem) => {
|
||||||
//there are devices to remove
|
//there are devices to remove
|
||||||
if (devicesToTurnOn.some((e) => e && e.name === value.DeviceName)) {
|
if (devicesToTurnOn.some((e) => e && e.name === value.DeviceName)) {
|
||||||
|
@ -24,7 +24,7 @@ export class CommandService {
|
|||||||
let commandName: string = "";
|
let commandName: string = "";
|
||||||
|
|
||||||
let device: HarmonyDevice = this._harmonyDataProvider.getDeviceByName(
|
let device: HarmonyDevice = this._harmonyDataProvider.getDeviceByName(
|
||||||
currentActivity.ControlDevice
|
currentActivity.currentActivity!.ControlDevice
|
||||||
);
|
);
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case RemoteKey.ARROW_UP: {
|
case RemoteKey.ARROW_UP: {
|
||||||
|
@ -16,10 +16,12 @@ export class VolumeService {
|
|||||||
*/
|
*/
|
||||||
public volumeUp = async (controlUnitName: string) => {
|
public volumeUp = async (controlUnitName: string) => {
|
||||||
let volumeUpCommand: string = "Volume Up";
|
let volumeUpCommand: string = "Volume Up";
|
||||||
let currentActivity = this._stateDataProvider.getState(controlUnitName);
|
let currentState = this._stateDataProvider.getState(controlUnitName);
|
||||||
if (currentActivity) {
|
if (currentState) {
|
||||||
let volumeDevice: HarmonyDevice =
|
let volumeDevice: HarmonyDevice =
|
||||||
this._harmonyDataProvider.getDeviceByName(currentActivity.VolumeDevice);
|
this._harmonyDataProvider.getDeviceByName(
|
||||||
|
currentState.currentActivity!.VolumeDevice
|
||||||
|
);
|
||||||
await this._harmonyDataProvider.sendCommand(
|
await this._harmonyDataProvider.sendCommand(
|
||||||
volumeUpCommand,
|
volumeUpCommand,
|
||||||
volumeDevice
|
volumeDevice
|
||||||
@ -32,10 +34,12 @@ export class VolumeService {
|
|||||||
*/
|
*/
|
||||||
public volumeDown = async (controlUnitName: string) => {
|
public volumeDown = async (controlUnitName: string) => {
|
||||||
let volumeDownCommand: string = "Volume Down";
|
let volumeDownCommand: string = "Volume Down";
|
||||||
let currentActivity = this._stateDataProvider.getState(controlUnitName);
|
let currentState = this._stateDataProvider.getState(controlUnitName);
|
||||||
if (currentActivity) {
|
if (currentState) {
|
||||||
let volumeDevice: HarmonyDevice =
|
let volumeDevice: HarmonyDevice =
|
||||||
this._harmonyDataProvider.getDeviceByName(currentActivity.VolumeDevice);
|
this._harmonyDataProvider.getDeviceByName(
|
||||||
|
currentState.currentActivity!.VolumeDevice
|
||||||
|
);
|
||||||
await this._harmonyDataProvider.sendCommand(
|
await this._harmonyDataProvider.sendCommand(
|
||||||
volumeDownCommand,
|
volumeDownCommand,
|
||||||
volumeDevice
|
volumeDevice
|
||||||
|
Reference in New Issue
Block a user