Skip to content

Commit

Permalink
Update TUYA driver version
Browse files Browse the repository at this point in the history
PR #174
- Update TUYA API major version (v6.1.1).
- New connection issues indicators on the light-app.
- More bugs fix and code clean up.
  • Loading branch information
haimkastner authored Dec 12, 2020
2 parents 8f2e941 + 7dc14ed commit ede55b5
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 113 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
npm ci
npm run test
bundle:
release:
needs: build
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
asset_content_type: application/octet-stream

bomb_version:
needs: bundle
needs: release
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
41 changes: 29 additions & 12 deletions backend/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 backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"rxjs": "^6.5.2",
"suncalc": "^1.8.0",
"tsoa": "2.4.3",
"tuyapi": "^5.3.1",
"tuyapi": "^6.1.1",
"winston": "^3.2.1",
"yeelight-awesome": "^1.0.12"
},
Expand Down
15 changes: 9 additions & 6 deletions backend/src/business-layer/remoteConnectionBl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,12 @@ export class RemoteConnectionBl {
return;
}

/** Before the channel opened, mark it as 'cantReachRemoteServer' (yet..) */
this.remoteConnectionStatus = 'cantReachRemoteServer';

/** create web socket instance */
this.webSocketClient = new WebSocketClient(3000, false);

/** Allow *only wss* connections. */
/** open connection to remote server. */
this.webSocketClient.connect(`${remoteSettings.host}`);

logger.info(`Opening ws channel to ${remoteSettings.host}`);

this.webSocketClient.on('open', () => {
this.remoteConnectionStatus = 'connectionOK';
logger.info(`Ws channel to ${remoteSettings.host} opened successfully`);
Expand Down Expand Up @@ -380,6 +377,12 @@ export class RemoteConnectionBl {
this.webSocketClient.on('reconnect', () => {
logger.debug(`Ws channel trying reconnect ${remoteSettings.host}`);
});

logger.info(`Opening ws channel to ${remoteSettings.host}`);

/** Allow *only wss* connections. */
/** open connection to remote server. */
this.webSocketClient.connect(`${remoteSettings.host}`);
}

private async onRemoteServerMessage(rawRemoteMessage: string) {
Expand Down
2 changes: 1 addition & 1 deletion backend/src/modules/brandModuleBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export abstract class BrandModuleBase {
public abstract readonly devices: DeviceKind[];

/**
* Let minions manager to know if any minion status changed by pysical interface of device.
* Let minions manager to know if any minion status changed by physical interface of device.
*/
public minionStatusChangedEvent = new BehaviorSubject<{
minionId: string;
Expand Down
14 changes: 7 additions & 7 deletions backend/src/modules/tuya/tuyaHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class TuyaHandler extends BrandModuleBase {
try {
const rowStatus = await tuyaDevice.get();

this.releaseDevice(tuyaDevice, minion.device);
this.watchDevice(tuyaDevice, minion.device);

return {
roller: {
Expand Down Expand Up @@ -153,7 +153,7 @@ export class TuyaHandler extends BrandModuleBase {
break;
}

this.releaseDevice(tuyaDevice, minion.device);
this.watchDevice(tuyaDevice, minion.device);

return {
switch: {
Expand All @@ -173,7 +173,7 @@ export class TuyaHandler extends BrandModuleBase {
await tuyaDevice.set({
set: setStatus.roller.status === 'off' ? '3' : setStatus.roller.direction === 'up' ? '1' : '2',
});
this.releaseDevice(tuyaDevice, minion.device);
this.watchDevice(tuyaDevice, minion.device);

return;
} catch (err) {
Expand Down Expand Up @@ -235,7 +235,7 @@ export class TuyaHandler extends BrandModuleBase {
} as ErrorResponse;
});

this.releaseDevice(tuyaDevice, minion.device);
this.watchDevice(tuyaDevice, minion.device);
}

public async enterRecordMode(minion: Minion, statusToRecordFor: MinionStatus): Promise<void | ErrorResponse> {
Expand Down Expand Up @@ -298,11 +298,11 @@ export class TuyaHandler extends BrandModuleBase {
}

/**
* On the se/get/ finished, call to this method to keep device and subscribe status events
* On the set/get finished, call to this method to keep device and subscribe status events
* @param tuyaDevice
* @param minionDevice
*/
private async releaseDevice(tuyaDevice: Tuyapi, minionDevice: MinionDevice) {
private async watchDevice(tuyaDevice: Tuyapi, minionDevice: MinionDevice) {

// Keep the device
this.pysicalDevicesMap[minionDevice.pysicalDevice.mac] = tuyaDevice;
Expand All @@ -325,7 +325,7 @@ export class TuyaHandler extends BrandModuleBase {

logger.debug(`tuya device mac: ${minionDevice.pysicalDevice.mac} data arrived`);

if (minionDevice.model.indexOf('curtain') !== -1) {
if (minionDevice.model.includes('curtain')) {
try {
const rowStatus = await tuyaDevice.get();

Expand Down
10 changes: 10 additions & 0 deletions frontend/src/light-app/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ body {
max-height: calc(100vh - 100px);
}

#connection-issue {
fill: #6dbdb9;
color: #6dbdb9;
}

#remote-issue {
fill: #6dbdb9;
color: #6dbdb9;
}

#power-on {
cursor: pointer;
fill: #6dbdb9;
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/light-app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@
d="M6 10c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm12 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm-6 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z" />
</svg>
</div>
<div id="remote-issue" class="hide">
<div style="margin-top: 13px;"></div>
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 24 24">
<path d="M0 0h24v24H0z" fill="none" />
<path
d="M19.35 10.04C18.67 6.59 15.64 4 12 4c-1.48 0-2.85.43-4.01 1.17l1.46 1.46C10.21 6.23 11.08 6 12 6c3.04 0 5.5 2.46 5.5 5.5v.5H19c1.66 0 3 1.34 3 3 0 1.13-.64 2.11-1.56 2.62l1.45 1.45C23.16 18.16 24 16.68 24 15c0-2.64-2.05-4.78-4.65-4.96zM3 5.27l2.75 2.74C2.56 8.15 0 10.77 0 14c0 3.31 2.69 6 6 6h11.73l2 2L21 20.73 4.27 4 3 5.27zM7.73 10l8 8H6c-2.21 0-4-1.79-4-4s1.79-4 4-4h1.73z" />
</svg>
</div>
<div id="connection-issue" class="hide">
<div style="margin-top: 13px;"></div>
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 24 24">
<path d="M0 0h24v24H0V0z" fill="none" />
<path
d="M11 15h2v2h-2zm0-8h2v6h-2zm.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" />
</svg>
</div>
</div>

<div class="dashboard-link-container">
Expand Down
Loading

0 comments on commit ede55b5

Please sign in to comment.