Skip to content

Commit

Permalink
chore: 🔖 prepare alpha release
Browse files Browse the repository at this point in the history
merge pull request #569 from johannrichard/next
  • Loading branch information
johannrichard authored Dec 30, 2022
2 parents c7470b3 + 23bee94 commit a2f0c8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
16 changes: 12 additions & 4 deletions src/myStromSwitchAccessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory {
)
.setCharacteristic(
this.platform.Characteristic.Model,
this.device.model as string,
`MyStrom WiFi Switch ${this.device.model as string}`,
)
.setCharacteristic(
this.platform.Characteristic.FirmwareRevision,
this.mystromDeviceInfo.version ?? 'N/A',
)
.setCharacteristic(
this.platform.Characteristic.HardwareRevision,
this.mystromDeviceInfo ? 'EU/CH v2/Zero' : 'CH v1',
this.device.model as string,
)
.setCharacteristic(
this.platform.Characteristic.SerialNumber,
Expand All @@ -89,7 +89,11 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory {
.on(CharacteristicEventTypes.GET, this.getOutletInUse.bind(this)); // GET - bind to the `getOn` method below

// Only EU and CH v2 Switches have temperature sensor
if (this.device.model !== 'Zero' && this.device.model !== undefined) {
if (
this.device.model !== 'Zero' &&
this.device.model !== 'CH v1' &&
this.device.model !== undefined
) {
// Switch has a temperature sensor, make it available here
this.temperatureService =
this.accessory.getService(this.platform.Service.TemperatureSensor) ??
Expand Down Expand Up @@ -134,7 +138,11 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory {
break;
}

if (this.temperatureService) {
if (
this.temperatureService &&
this.outletState.temperature !== null &&
this.outletState.temperature !== undefined
) {
this.temperatureService
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
.updateValue(this.outletState.temperature);
Expand Down
19 changes: 11 additions & 8 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
} from 'homebridge';
import { Policy, ConsecutiveBreaker } from 'cockatiel';
import { createSocket, Socket, RemoteInfo } from 'dgram';
import { isNativeError } from 'util/types';
import axios, { AxiosError } from 'axios';
import axiosRetry from 'axios-retry';
import * as bodyParser from 'body-parser';
Expand Down Expand Up @@ -1052,9 +1053,9 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
process.on('exit', () => {
try {
discoverySocket.close();
} catch (e: any) {
if (e.code === 'ERR_SOCKET_DGRAM_NOT_CONNECTED') {
this.log.info('Socket already destroyed');
} catch (e: unknown) {
if (isNativeError(e)) {
this.log.error(`${e.name}: ${e.message}`);
}
} finally {
this.log.info('Process ended, socket destroyed');
Expand All @@ -1068,15 +1069,17 @@ export class DingzDaHomebridgePlatform implements DynamicPlatformPlugin {
this.log.info('Stopping discovery');
try {
discoverySocket.close();
} catch (e: any) {
if (e.code === 'ERR_SOCKET_DGRAM_NOT_CONNECTED') {
this.log.info('Socket already destroyed');
} catch (e: unknown) {
if (isNativeError(e)) {
this.log.error(`${e.name}: ${e.message}`);
}
}
}, 600000); // Discover for 10 min then stop
// Make sure we close the socket even if we get killed
} catch (e: any) {
this.log.error(e.code + ' Socket error');
} catch (e: unknown) {
if (isNativeError(e)) {
this.log.error(`${e.name}: ${e.message}`);
}
}
return true;
}
Expand Down

0 comments on commit a2f0c8e

Please sign in to comment.