Skip to content

Commit

Permalink
Change humidityUnit to maxHumidity
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Krug <[email protected]>
  • Loading branch information
michikrug committed May 31, 2024
1 parent b7e69dc commit 5e85c45
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 20 deletions.
8 changes: 4 additions & 4 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ Number pm25Item (fanGroup) { ga="fanPM25" }
| **Device Type** | [AC_Unit](https://developers.google.com/assistant/smarthome/guides/acunit) |
| **Supported Traits** | [OnOff](https://developers.google.com/assistant/smarthome/traits/OnOff), [FanSpeed](https://developers.google.com/assistant/smarthome/traits/fanspeed), [TemperatureSetting](https://developers.google.com/assistant/smarthome/traits/temperaturesetting), [Modes](https://developers.google.com/assistant/smarthome/traits/modes), [SensorState](https://developers.google.com/assistant/smarthome/traits/sensorstate) |
| **Supported Items** | Group as `AC_Unit` with the following members:<br>(optional) Switch as `fanPower`<br>(optional) Dimmer or Number as `fanSpeed`<br>(optional) Number or String as `fanMode`<br>(optional) Number as `fanFilterLifeTime`<br>(optional) Number as `fanPM25`<br>(optional) Number as `thermostatTemperatureAmbient`<br>(optional) Number as `thermostatTemperatureSetpoint`<br>(optional) Number as `thermostatTemperatureSetpointLow`<br>(optional) Number as `thermostatTemperatureSetpointHigh`<br>(optional) Number as `thermostatHumidityAmbient`<br>(optional) String or Number or Switch as `thermostatMode` |
| **Configuration** | (optional) `checkState=true/false`<br>(optional) `fanSpeeds="0=away:zero,50=default:standard:one,100=high:two"`<br>(optional) `fanModeName="OperationMode,Modus"`<br>(optional) `fanModeSettings="1=Low:Silent,2=Normal,3=High:Night"`<br>(optional) `useFahrenheit=true/false`<br>(optional) `humidityUnit=percent/float`<br>(optional) `thermostatTemperatureRange="10,30"`<br>(optional) `thermostatModes="off=OFF:WINDOW_OPEN,heat=COMFORT:BOOST,eco=ECO,on=ON,auto"`<br>(optional) `lang="en"`<br>(optional) `ordered=true/false` |
| **Configuration** | (optional) `checkState=true/false`<br>(optional) `fanSpeeds="0=away:zero,50=default:standard:one,100=high:two"`<br>(optional) `fanModeName="OperationMode,Modus"`<br>(optional) `fanModeSettings="1=Low:Silent,2=Normal,3=High:Night"`<br>(optional) `useFahrenheit=true/false`<br>(optional) `maxHumidity=1-100`<br>(optional) `thermostatTemperatureRange="10,30"`<br>(optional) `thermostatModes="off=OFF:WINDOW_OPEN,heat=COMFORT:BOOST,eco=ECO,on=ON,auto"`<br>(optional) `lang="en"`<br>(optional) `ordered=true/false` |
The AC_Unit device is basically the combination of the Fan and the Thermostat device. For explanation on configuration options please take a look at both of them.
Expand Down Expand Up @@ -486,7 +486,7 @@ Number { ga="TemperatureSensor" [ useFahrenheit=true, temperatureRange="-20,40"
| **Device Type** | [Sensor](https://developers.home.google.com/cloud-to-cloud/guides/sensor) |
| **Supported Traits** | [HumiditySetting](https://developers.home.google.com/cloud-to-cloud/traits/humiditysetting) |
| **Supported Items** | Number |
| **Configuration** | (optional) `humidityUnit=percent/float` |
| **Configuration** | (optional) `maxHumidity=1-100` |
```shell
Number { ga="HumiditySensor" }
Expand All @@ -499,7 +499,7 @@ Number { ga="HumiditySensor" }
| **Device Type** | [Sensor](https://developers.home.google.com/cloud-to-cloud/guides/sensor) |
| **Supported Traits** | [HumiditySetting](https://developers.home.google.com/cloud-to-cloud/traits/humiditysetting), [TemperatureControl](https://developers.home.google.com/cloud-to-cloud/traits/temperaturecontrol), [TemperatureSetting](https://developers.home.google.com/cloud-to-cloud/traits/temperaturesetting) |
| **Supported Items** | Group as `ClimateSensor` with the following members:<br>(optional) Number as `humidityAmbient`<br>(optional) Number as `temperatureAmbient` |
| **Configuration** | (optional) `useFahrenheit=true/false`<br>(optional) `humidityUnit=percent/float`<br>(optional) `temperatureRange="-10,50"` |
| **Configuration** | (optional) `useFahrenheit=true/false`<br>(optional) `maxHumidity=1-100`<br>(optional) `temperatureRange="-10,50"` |
By default, the temperature range of a climate sensor is set to -100 °C to 100 °C.
The reported state values have to fall into that range!
Expand All @@ -518,7 +518,7 @@ Number humidityItem (sensorGroup) { ga="humidityAmbient" }
| **Device Type** | [Thermostat](https://developers.home.google.com/cloud-to-cloud/guides/thermostat) |
| **Supported Traits** | [TemperatureSetting](https://developers.home.google.com/cloud-to-cloud/traits/temperaturesetting) |
| **Supported Items** | Group as `Thermostat` with the following members<br>(optional) Number as `thermostatTemperatureAmbient`<br>(optional) Number as `thermostatTemperatureSetpoint`<br>(optional) Number as `thermostatTemperatureSetpointLow`<br>(optional) Number as `thermostatTemperatureSetpointHigh`<br>(optional) Number as `thermostatHumidityAmbient`<br>(optional) String or Number or Switch as `thermostatMode` |
| **Configuration** | (optional) `checkState=true/false`<br>(optional) `useFahrenheit=true/false`<br>(optional) `humidityUnit=percent/float`<br>(optional) `thermostatTemperatureRange="10,30"`<br>(optional) `thermostatModes="off=OFF:WINDOW_OPEN,heat=COMFORT:BOOST,eco=ECO,on=ON,auto"` |
| **Configuration** | (optional) `checkState=true/false`<br>(optional) `useFahrenheit=true/false`<br>(optional) `maxHumidity=1-100`<br>(optional) `thermostatTemperatureRange="10,30"`<br>(optional) `thermostatModes="off=OFF:WINDOW_OPEN,heat=COMFORT:BOOST,eco=ECO,on=ON,auto"` |
Thermostat requires a group of items to be properly configured to be used with Google Assistant. The default temperature unit is Celsius.
To change the temperature unit to Fahrenheit, add the config option `useFahrenheit=true` to the thermostat group.
Expand Down
4 changes: 2 additions & 2 deletions functions/devices/climatesensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class ClimateSensor extends DefaultDevice {
}
if ('humidityAmbient' in members) {
const config = this.getConfig(item);
const isPercent = !config.humidityUnit || config.humidityUnit.toLowerCase() === 'percent';
const humidity = Math.round(parseFloat(members.humidityAmbient.state) * (isPercent ? 1 : 100));
const maxHumidity = (config.maxHumidity && parseInt(config.maxHumidity)) || 100;
const humidity = Math.round(parseFloat(members.humidityAmbient.state) * (100 / maxHumidity));
state.humidityAmbientPercent = humidity;
state.humiditySetpointPercent = humidity;
}
Expand Down
4 changes: 2 additions & 2 deletions functions/devices/humiditysensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class HumiditySensor extends DefaultDevice {

static getState(item) {
const config = this.getConfig(item);
const isPercent = !config.humidityUnit || config.humidityUnit.toLowerCase() === 'percent';
const state = Math.round(parseFloat(item.state) * (isPercent ? 1 : 100));
const maxHumidity = (config.maxHumidity && parseInt(config.maxHumidity)) || 100;
const state = Math.round(parseFloat(item.state) * (100 / maxHumidity));
return {
humidityAmbientPercent: state,
humiditySetpointPercent: state
Expand Down
4 changes: 2 additions & 2 deletions functions/devices/thermostat.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class Thermostat extends DefaultDevice {
}
if (member.indexOf('Humidity') > 0) {
const config = this.getConfig(item);
const isPercent = !config.humidityUnit || config.humidityUnit.toLowerCase() === 'percent';
state[member] = Math.round(parseFloat(members[member].state) * (isPercent ? 1 : 100));
const maxHumidity = (config.maxHumidity && parseInt(config.maxHumidity)) || 100;
state[member] = Math.round(parseFloat(members[member].state) * (100 / maxHumidity));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/devices/climatesensor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('ClimateSensor Device', () => {
metadata: {
ga: {
config: {
humidityUnit: 'float'
maxHumidity: 1
}
}
},
Expand Down
12 changes: 5 additions & 7 deletions tests/devices/humiditysensor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ describe('HumiditySensor Device', () => {
});
});

test('getState humidityUnit float', () => {
expect(Device.getState({ state: '0.34', metadata: { ga: { config: { humidityUnit: 'float' } } } })).toStrictEqual(
{
humidityAmbientPercent: 34,
humiditySetpointPercent: 34
}
);
test('getState maxHumidity', () => {
expect(Device.getState({ state: '0.34', metadata: { ga: { config: { maxHumidity: 1 } } } })).toStrictEqual({
humidityAmbientPercent: 34,
humiditySetpointPercent: 34
});
});
});
});
4 changes: 2 additions & 2 deletions tests/devices/thermostat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,12 @@ describe('Thermostat Device', () => {
});
});

test('getState only humdity with unit', () => {
test('getState only humdity with maxHumidity', () => {
const item = {
metadata: {
ga: {
config: {
humidityUnit: 'float'
maxHumidity: 1
}
}
},
Expand Down

0 comments on commit 5e85c45

Please sign in to comment.