diff --git a/src/myStromSwitchAccessory.ts b/src/myStromSwitchAccessory.ts index bc4b4b4..508ca72 100644 --- a/src/myStromSwitchAccessory.ts +++ b/src/myStromSwitchAccessory.ts @@ -54,7 +54,7 @@ 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, @@ -62,7 +62,7 @@ export class MyStromSwitchAccessory extends DingzDaBaseAccessory { ) .setCharacteristic( this.platform.Characteristic.HardwareRevision, - this.mystromDeviceInfo ? 'EU/CH v2/Zero' : 'CH v1', + this.device.model as string, ) .setCharacteristic( this.platform.Characteristic.SerialNumber, @@ -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) ?? @@ -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); diff --git a/src/platform.ts b/src/platform.ts index e39c931..f7aa149 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -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'; @@ -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'); @@ -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; }