diff --git a/.homeychangelog.json b/.homeychangelog.json index 2ba90a5..d663b65 100644 --- a/.homeychangelog.json +++ b/.homeychangelog.json @@ -166,5 +166,8 @@ }, "1.0.4": { "en": "Fixed bug in updaing level of dimmers from bus" + }, + "1.0.5": { + "en": "Refactoring value checks and fixed ug in multisensor lux, temperature and movement" } } diff --git a/.homeycompose/app.json b/.homeycompose/app.json index 33fc605..3f7be9b 100644 --- a/.homeycompose/app.json +++ b/.homeycompose/app.json @@ -1,6 +1,6 @@ { "id": "com.github.alydersen.hdl-smartbus-homey", - "version": "1.0.4", + "version": "1.0.5", "compatibility": ">=5.0.0", "sdk": 3, "name": { diff --git a/DEVICES_DIMMERS.md b/DEVICES_DIMMERS.md index 97d3aea..5e1b6c7 100644 --- a/DEVICES_DIMMERS.md +++ b/DEVICES_DIMMERS.md @@ -1,7 +1,7 @@ [Back to the main page](index.md) # Dimmers -A dimmer controller have one or more dimmers as channels. Different HDL Models have different number of channels, and you see this in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/v1.0.4/hdl/hdl_devicelist.js) under each type as "channels". You always add each separate channel as a Homey device, and they will as such be shown indivdually in the process of adding them. +A dimmer controller have one or more dimmers as channels. Different HDL Models have different number of channels, and you see this in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/master/hdl/hdl_devicelist.js) under each type as "channels". You always add each separate channel as a Homey device, and they will as such be shown indivdually in the process of adding them. Dimmers are a built-in capability in Homey, and as such have very good Homey support. diff --git a/DEVICES_MULTISENSORS.md b/DEVICES_MULTISENSORS.md index 9cab45e..0531068 100644 --- a/DEVICES_MULTISENSORS.md +++ b/DEVICES_MULTISENSORS.md @@ -17,7 +17,7 @@ As you can see in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus- Keep in mind that since homey needs to have received a signal containing the capability's state before the capability is added, several minutes can go by before you have a device with all it's capabilites in Homey. ### Exclusions -Sometimes the signal from a device will contain state for a capability that is not supported for it. [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/v1.0.4/hdl/hdl_devicelist.js) contains a "exclude" option for these per device type, so that it will be disregarded. If you want more added here - follow the [Contribution guidelines](CONTRIBUTING.md) +Sometimes the signal from a device will contain state for a capability that is not supported for it. [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/master/hdl/hdl_devicelist.js) contains a "exclude" option for these per device type, so that it will be disregarded. If you want more added here - follow the [Contribution guidelines](CONTRIBUTING.md) ## Making motion stable The different multisensor types handles motion a bit different, making trusting the signal received a bit difficult. If you want this to be stable, configure your sensor to send an Universal Switch (UVS) with the value set to "ON" to the device ID of your Homey app. The UVS number that the app will expect is 212, but you can change this in the settings. The ID of your Homey App is configured in your settings. You should also add a similar action for "OFF" sent to the same ID. diff --git a/DEVICES_RELAYS.md b/DEVICES_RELAYS.md index f913742..f4a499a 100644 --- a/DEVICES_RELAYS.md +++ b/DEVICES_RELAYS.md @@ -1,6 +1,6 @@ [Back to the main page](index.md) # Relays -A relay controller have one or more on/off capable channels. Different HDL Models have different number of channels, and you see this in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/v1.0.4/hdl/hdl_devicelist.js) under each type as "channels". You always add each separate channel as a Homey device, and they will as such be shown indivdually in the process of adding them. +A relay controller have one or more on/off capable channels. Different HDL Models have different number of channels, and you see this in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/master/hdl/hdl_devicelist.js) under each type as "channels". You always add each separate channel as a Homey device, and they will as such be shown indivdually in the process of adding them. ON/OFF switches are a built-in capability in Homey, and as such have very good Homey support. diff --git a/DEVICES_TEMPSENSORS.md b/DEVICES_TEMPSENSORS.md index ea95630..743346b 100644 --- a/DEVICES_TEMPSENSORS.md +++ b/DEVICES_TEMPSENSORS.md @@ -1,7 +1,7 @@ [Back to the main page](index.md) # Temperature Sensors -A temperature sensor controller have one or more temperature sensors as channels. Different HDL Models have different number of channels, and you see this in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/v1.0.4/hdl/hdl_devicelist.js) under each type as "channels". You always add each separate channel as a Homey device, and they will as such be shown indivdually in the process of adding them. +A temperature sensor controller have one or more temperature sensors as channels. Different HDL Models have different number of channels, and you see this in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/master/hdl/hdl_devicelist.js) under each type as "channels". You always add each separate channel as a Homey device, and they will as such be shown indivdually in the process of adding them. Temperature sensors are a built-in capability in Homey, and as such have very good Homey support. diff --git a/app.js b/app.js index 56049e3..90509cb 100644 --- a/app.js +++ b/app.js @@ -150,6 +150,25 @@ class HDLSmartBus extends Homey.App { return this._hdlFoundUnits[drivername]; } + valueOK(type, value) { + if (typeof value === "undefined") return false; + switch (type) { + case "temperature": + if (! typeof value === "number") return false; + if (value < -40 || value > 80) return false; + return true; + case "humidity": + if (! typeof value === "number") return false; + if (value < 0 || value > 100) return false; + return true; + case "lux": + if (! typeof value === "number") return false; + if (value < 0 || value > 100000) return false; + return true; + } + return true; + } + async _updateDevice(hdlSenderType, signal) { const unknownDeviceMessages = ["invalid_device", "device is not defined", "Could not get device by device data"] await this.homey.drivers.getDriver(hdlSenderType).updateValues(signal).catch((error) => { diff --git a/app.json b/app.json index 5be6464..b5f873f 100644 --- a/app.json +++ b/app.json @@ -1,7 +1,7 @@ { "_comment": "This file is generated. Please edit .homeycompose/app.json instead.", "id": "com.github.alydersen.hdl-smartbus-homey", - "version": "1.0.4", + "version": "1.0.5", "compatibility": ">=5.0.0", "sdk": 3, "name": { diff --git a/drivers/multisensor/driver.js b/drivers/multisensor/driver.js index f6f9ee3..e9da778 100644 --- a/drivers/multisensor/driver.js +++ b/drivers/multisensor/driver.js @@ -12,7 +12,7 @@ class MultisensorDriver extends Homey.Driver { async checkCapabilityAdded(device, capability) { if (! (device.hasCapability(capability))) { - device.addCapability(capability).catch(this.error); + await device.addCapability(capability).catch(this.error); } } @@ -26,10 +26,10 @@ class MultisensorDriver extends Homey.Driver { let hdlUVSwitch = parseInt(this.homey.settings.get("hdl_universal_motion")); // Check which signals are present and range - let hasTemp = signal.data.temperature != undefined && (signal.data.temperature < -40 || signal.data.temperature > 70); - let hasHum = signal.data.humidity != undefined && (signal.data.humidity < 0 || signal.data.humidity > 100); - let hasLux = signal.data.lux != undefined && (signal.data.lux < 0 || signal.data.lux > 100000); - let hasMotion = signal.data.motion != undefined; + let hasTemp = this.homey.app.valueOK("temperature", signal.data.temperature); + let hasHum = this.homey.app.valueOK("humidity", signal.data.humidity); + let hasLux = this.homey.app.valueOK("lux", signal.data.brightness); + let hasMotion = signal.data.movement != undefined; let hasDryContact = signal.data.dryContacts != undefined; let hasUV = signal.data.switch != undefined && signal.data.status != undefined && hdlUVSwitch == signal.data.switch; diff --git a/drivers/tempsensor/driver.js b/drivers/tempsensor/driver.js index e4b2348..8edf5db 100644 --- a/drivers/tempsensor/driver.js +++ b/drivers/tempsensor/driver.js @@ -16,7 +16,7 @@ class TempsensorDriver extends Homey.Driver { if (signal.sender.id == undefined) return; // Disregard signals if the readings are out of range - if (signal.data.temperature < -40 || signal.data.temperature > 70) return; + if (!this.homey.app.valueOK("temperature", signal.data.temperature)) return; // Get the device from Homey, return if not found or error let hdl_subnet = this.homey.settings.get("hdl_subnet"); diff --git a/index.md b/index.md index c68ed82..3806dcf 100644 --- a/index.md +++ b/index.md @@ -17,7 +17,7 @@ You can find trubleshooting tips in the connection howto link above. If you are a developer and want to add a new driver for the app, read the [Contribution guidelines](CONTRIBUTING.md). ### How devices are recognized -The App will listen to signals on the bus. For each signal, it will look into the sender type id and check that against a list of supported devices. A list of devices known by the documentation can be found [this Excel file](https://github.com/alydersen/hdl-smartbus-homey/blob/v1.0.4/assets/defDeviceType.xlsx) (the type IDs from column A). TheID is then used in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/v1.0.4/hdl/hdl_devicelist.js) to connect it to a specific driver. Sometimes more device types can simply be added to hdl_devicelist.js to be known. If you suspect this to be the case, raise an [Issue in Github](CONTRIBUTING.md). Universal Switches are different, so read up on them below. +The App will listen to signals on the bus. For each signal, it will look into the sender type id and check that against a list of supported devices. A list of devices known by the documentation can be found [this Excel file](https://github.com/alydersen/hdl-smartbus-homey/blob/master/assets/defDeviceType.xlsx) (the type IDs from column A). TheID is then used in [hdl_devicelist.js](https://github.com/alydersen/hdl-smartbus-homey/blob/master/hdl/hdl_devicelist.js) to connect it to a specific driver. Sometimes more device types can simply be added to hdl_devicelist.js to be known. If you suspect this to be the case, raise an [Issue in Github](CONTRIBUTING.md). Universal Switches are different, so read up on them below. ### How the device state is set Devices broadcasts their state on the bus and the Homey App reads them and updates the state on your Homey device if it is added. Sometimes, state is not published as it is happening (for various reasons). The app will reach out to every device every minute with a signal on the bus to make it publish its state. This means that sometimes, you'll have to wait a minute before you have an updated state. diff --git a/package-lock.json b/package-lock.json index a62f6f3..0326259 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "com.github.alydersen.homey-smartbus", - "version": "1.0.4", + "version": "1.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "com.github.alydersen.homey-smartbus", - "version": "1.0.4", + "version": "1.0.5", "dependencies": { "smart-bus": "^0.6.0" }, diff --git a/package.json b/package.json index 97270df..c8249ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.github.alydersen.homey-smartbus", - "version": "1.0.4", + "version": "1.0.5", "main": "app.js", "devDependencies": { "@types/homey": "npm:homey-apps-sdk-v3-types@^0.3.1"