Skip to content

Commit

Permalink
chore: 🔖 prepare alpha release
Browse files Browse the repository at this point in the history
Merge pull request #571 from johannrichard/next
  • Loading branch information
johannrichard authored Dec 30, 2022
2 parents 8f603ef + 054e3c6 commit 723eb75
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
25 changes: 21 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 All @@ -103,6 +107,15 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory {
this.temperatureService
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
.on(CharacteristicEventTypes.GET, this.getTemperature.bind(this));
} else {
// Make sure spurious temperature services (e.g. from Zero and CH v1) don't remain in the system
const temperatureService: Service | undefined = this.accessory.getService(
this.platform.Service.TemperatureSensor,
);
if (temperatureService !== undefined) {
this.platform.log.warn('Removing spurious temperature service');
this.accessory.removeService(temperatureService);
}
}
}

Expand Down Expand Up @@ -134,7 +147,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 723eb75

Please sign in to comment.