Skip to content

Commit

Permalink
Merge branch 'main' into own-main
Browse files Browse the repository at this point in the history
  • Loading branch information
michikrug committed Oct 19, 2023
2 parents 10c44ff + c036f3a commit 01dbbbc
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 67 deletions.
23 changes: 14 additions & 9 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ If you have any issues, questions or an idea for additional features, please tak
## Latest Changes

::: tip State of this document
This documentation refers to release [v3.6.5](https://github.com/openhab/openhab-google-assistant/releases/tag/v3.6.5) of [openHAB Google Assistant](https://github.com/openhab/openhab-google-assistant) published on 2023-07-17
This documentation refers to release [v3.7.0](https://github.com/openhab/openhab-google-assistant/releases/tag/v3.7.0) of [openHAB Google Assistant](https://github.com/openhab/openhab-google-assistant) published on 2023-10-10
:::

### v3.7.0

- Adjusted [`Fan`](#fan-hood-airpurifier) to use `supportsFanSpeedPercent` option
- Inverted `lightColorTemperature` percentage range when using `colorUnit="percent"` with [`SpecialColorLight`](#light-as-group-with-separate-controls)

### v3.6.0

- Added new device types [`HumiditySensor`](#humiditysensor) & [`ClimateSensor`](#climatesensor)
Expand Down Expand Up @@ -94,7 +99,7 @@ Color { ga="Light" [ colorTemperatureRange="2000,9000" ] }
| **Device Type** | [Light](https://developers.home.google.com/cloud-to-cloud/guides/light) |
| **Supported Traits** | [OnOff](https://developers.home.google.com/cloud-to-cloud/traits/onoff), [ColorSetting](https://developers.home.google.com/cloud-to-cloud/traits/colorsetting), [Brightness](https://developers.home.google.com/cloud-to-cloud/traits/brightness) |
| **Supported Items** | Group as `SpecialColorLight` with the following members:<br>(optional) Number or Dimmer as `lightBrightness`<br>(optional) Number or Dimmer as `lightColorTemperature`<br>(optional) Color as `lightColor`<br>(optional) Switch as `lightPower` |
| **Configuration** | (optional) `colorUnit=percent/kelvin/mired`<br>(optional) `checkState=true/false`<br>(optional) `colorTemperatureRange="minK,maxK"`<br>_Hint: if you want to use `lightColorTemperature` you either need to set `colorUnit` to `kelvin` or `mired` or define a `colorTemperatureRange` as `colorUnit` defaults to `percent`_ |
| **Configuration** | (optional) `colorUnit="percent/kelvin/mired"`<br>(optional) `checkState=true/false`<br>(optional) `colorTemperatureRange="minK,maxK"`<br>_Hint: if you want to use `lightColorTemperature`, you must either set `colorUnit` to `kelvin` or `mired` or define a `colorTemperatureRange`, because `colorUnit` defaults to `percent`_ |
```shell
Group lightGroup { ga="SpecialColorLight" [ colorUnit="kelvin", colorTemperatureRange="2000,9000" ] }
Expand Down Expand Up @@ -200,7 +205,7 @@ Switch { ga="Lock" [ pinNeeded="1234" ] }
| **Device Type** | [SecuritySystem](https://developers.home.google.com/cloud-to-cloud/guides/securitysystem) |
| **Supported Traits** | [ArmDisarm](https://developers.home.google.com/cloud-to-cloud/traits/armdisarm) |
| **Supported Items** | Switch |
| **Configuration** | (optional) `inverted=true/false`<br>(optional) `checkState=true/false`<br>(optional) `ackNeeded=true/false`<br>(optional) `pinNeeded="1234"`<br>(optional) `pinOnDisarmOnly=true/false`<br>(optional) `waitForStateChange=2` |
| **Configuration** | (optional) `inverted=true/false`<br>(optional) `checkState=true/false`<br>(optional) `ackNeeded=true/false`<br>(optional) `pinNeeded="1234"`<br>(optional) `pinOnDisarmOnly=true/false`<br>(optional) `waitForStateChange="2"` |
When used as a Switch, you will be limited to arming and disarming the system.
Expand All @@ -219,7 +224,7 @@ Switch houseAlarm "House Alarm" { ga="SecuritySystem", pinNeeded="1234" }
| **Device Type** | [SecuritySystem](https://developers.home.google.com/cloud-to-cloud/guides/securitysystem) |
| **Supported Traits** | [ArmDisarm](https://developers.home.google.com/cloud-to-cloud/traits/armdisarm)<br>[StatusReport](https://developers.home.google.com/cloud-to-cloud/traits/statusreport) |
| **Supported Items** | Group as `SecuritySystem` with the following members: <br>Switch as `securitySystemArmed`<br>(optional) String as `securitySystemArmLevel`<br>(optional) Switch as `securitySystemTrouble`<br>(optional) String as `securitySystemTroubleCode`<br>(optional) Contact as `securitySystemZone` |
| **Configuration** | (optional) `inverted=true/false`<br>(optional) `checkState=true/false`<br>(optional) `ackNeeded=true/false`<br>(optional) `pinNeeded="1234"`<br> (optional) `pinOnDisarmOnly=true/false` <br>(optional) `waitForStateChange=2`<br>(optional) `armLevels="L1=Level 1,L2=Level 2"`<br><br>Specifically on Zone Contacts:<br>(required) `zoneType=OpenClose/Motion` <br>(optional) `blocking=true/false`|
| **Configuration** | (optional) `inverted=true/false`<br>(optional) `checkState=true/false`<br>(optional) `ackNeeded=true/false`<br>(optional) `pinNeeded="1234"`<br> (optional) `pinOnDisarmOnly=true/false` <br>(optional) `waitForStateChange="2"`<br>(optional) `armLevels="L1=Level 1,L2=Level 2"`<br><br>Specifically on Zone Contacts:<br>(required) `zoneType="OpenClose/Motion"` <br>(optional) `blocking=true/false`|
Configuring the `SecuritySystem` as a Group will enable a lot of advanced functionality.
Expand All @@ -243,7 +248,7 @@ When arming and not using arm levels or disarming, Google will send ON/OFF to th
If arming fails and blocking zones have been configured with `securitySystemZone` and `blocking=true`, Google will attempt to check for zones that are causing the arming to fail.
`ga=securitySystemTrouble` and `ga=securitySystemTroubleCode` are used in a `StatusReport` to report any errors on the alarm, e.g. a flat battery.
`ga="securitySystemTrouble"` and `ga="securitySystemTroubleCode"` are used in a `StatusReport` to report any errors on the alarm, e.g. a flat battery.
```shell
Group gHouseAlarm "House Alarm" { ga="SecuritySystem" [ pinNeeded="1234", armLevels="L1=Level 1,L2=Level 2" ] }
Expand Down Expand Up @@ -307,7 +312,7 @@ Player transportItem (tvGroup) { ga="tvTransport" }
| **Device Type** | [Fan](https://developers.home.google.com/cloud-to-cloud/guides/fan), [Hood](https://developers.home.google.com/cloud-to-cloud/guides/hood), [AirPurifier](https://developers.home.google.com/cloud-to-cloud/guides/airpurifier) |
| **Supported Traits** | [OnOff](https://developers.home.google.com/cloud-to-cloud/traits/OnOff), [FanSpeed](https://developers.home.google.com/cloud-to-cloud/traits/fanspeed) (depending on used item type) |
| **Supported Items** | Switch (no speed control), Dimmer |
| **Configuration** | (optional) `checkState=true/false`<br>(optional) `speeds="0=away:zero,50=default:standard:one,100=high:two"`<br>(optional) `lang="en"`<br>(optional) `ordered=true/false`<br>_Hint: if you are using a Dimmer then `speeds` is required_ |
| **Configuration** | (optional) `checkState=true/false`<br>(optional) `speeds="0=away:zero,50=default:standard:one,100=high:two"`<br>(optional) `lang="en"`<br>(optional) `ordered=true/false` |
Fans (and similar device types, like AirPurifier or Hood) support the `FanSpeed` trait.
If you do not specify the `speeds` option, Google will use and expect percentage values for the fan speed.
Expand All @@ -320,10 +325,10 @@ You are also able to define the language of those aliases.
The option `ordered` will tell the system that your list is ordered and you will then be able to also say "faster" or "slower" and Google will use the next or previous speed.
```shell
Dimmer { ga="Fan" [ speeds="0=away:zero,50=default:standard:one,100=high:two", lang="en", ordered=true ] } # Only percentage values for the speed
Dimmer { ga="Fan" [ speeds="0=away:zero,50=default:standard:one,100=high:two", lang="en", ordered=true ] } # Using specific percentage values for the speed
Switch { ga="Hood" } # No speed control - only on/off
Dimmer { ga="AirPurifier" } # Only percentage values for the speed
Dimmer { ga="AirPurifier" [ speeds="0=away:zero,1=low:one,2=medium:two,3=high:three,4=turbo:four", lang="en", ordered=true ] } # Specific speed modes/values stated, which can differ from percentage
Dimmer { ga="AirPurifier" } # Using percentage values for the speed
Dimmer { ga="AirPurifier" [ speeds="0=away:zero,1=low:one,2=medium:two,3=high:three,4=turbo:four", lang="en", ordered=true ] } # Using specific speed modes/values, which differ from percentage
Switch { ga="AirPurifier" } # No speed control - only on/off
```
Expand Down
5 changes: 1 addition & 4 deletions functions/commands/colorabsolutetemperature.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ class ColorAbsoluteTemperature extends DefaultCommand {
return convertMired(params.color.temperature).toString();
}
const { temperatureMinK, temperatureMaxK } = SpecialColorLight.getAttributes(item).colorTemperatureRange;
return (
100 -
((params.color.temperature - temperatureMinK) / (temperatureMaxK - temperatureMinK)) * 100
).toString();
return (((params.color.temperature - temperatureMinK) / (temperatureMaxK - temperatureMinK)) * 100).toString();
} catch (error) {
return '0';
}
Expand Down
23 changes: 23 additions & 0 deletions functions/commands/setfanspeedpercent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const DefaultCommand = require('./default.js');

class SetFanSpeedPercent extends DefaultCommand {
static get type() {
return 'action.devices.commands.SetFanSpeed';
}

static validateParams(params) {
return 'fanSpeedPercent' in params && typeof params.fanSpeedPercent === 'number';
}

static convertParamsToValue(params) {
return params.fanSpeedPercent.toString();
}

static getResponseStates(params) {
return {
currentFanSpeedPercent: params.fanSpeedPercent
};
}
}

module.exports = SetFanSpeedPercent;
14 changes: 11 additions & 3 deletions functions/devices/fan.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Fan extends DefaultDevice {
static getAttributes(item) {
const config = this.getConfig(item);
if (!config || !config.speeds) {
return {};
return {
supportsFanSpeedPercent: true
};
}
const attributes = {
availableFanSpeeds: {
Expand Down Expand Up @@ -49,10 +51,16 @@ class Fan extends DefaultDevice {
}

static getState(item) {
return {
currentFanSpeedSetting: item.state.toString(),
const state = {
on: Number(item.state) > 0
};
const config = this.getConfig(item);
if (config && config.speeds) {
state.currentFanSpeedSetting = item.state.toString();
} else {
state.currentFanSpeedPercent = Math.round(Number(item.state));
}
return state;
}
}

Expand Down
2 changes: 1 addition & 1 deletion functions/devices/specialcolorlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SpecialColorLight extends DefaultDevice {
state.color = {
temperatureK:
temperatureMinK +
Math.round(((temperatureMaxK - temperatureMinK) / 100) * (100 - Number(members[member].state)) || 0)
Math.round(((temperatureMaxK - temperatureMinK) / 100) * Number(members[member].state) || 0)
};
}
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions functions/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 functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openhab.google-assistant-smarthome.cloud-function",
"version": "3.6.5",
"version": "3.7.0",
"description": "A Google Assistant, Actions on Google based implementation for openHAB",
"repository": {
"type": "git",
Expand Down
74 changes: 37 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "openhab.google-assistant-smarthome",
"version": "3.6.5",
"version": "3.7.0",
"description": "A Google Assistant, Actions on Google based implementation for openHAB",
"main": "functions/index.js",
"repository": {
Expand Down Expand Up @@ -36,11 +36,11 @@
},
"devDependencies": {
"@types/jest": "^29.5.5",
"eslint": "^8.50.0",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"nock": "^13.3.3",
"nock": "^13.3.4",
"prettier": "3.0.3"
}
}
2 changes: 1 addition & 1 deletion tests/commands/colorabsolutetemperature.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('ColorAbsoluteTemperature Command', () => {
}
};
const device = { customData: { deviceType: 'SpecialColorLight' } };
expect(Command.convertParamsToValue(params, item, device)).toBe('75');
expect(Command.convertParamsToValue(params, item, device)).toBe('25');
expect(Command.convertParamsToValue(params, { state: '100,100,50' }, device)).toBe('0');
});

Expand Down
Loading

0 comments on commit 01dbbbc

Please sign in to comment.