Skip to content

Commit

Permalink
Proper value ranges for type light
Browse files Browse the repository at this point in the history
  • Loading branch information
DutchmanNL committed Mar 2, 2021
1 parent 3140da2 commit 53217c9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ switch:
Placeholder for the next version (at the beginning of the line):
### __WORK IN PROGRESS__
-->
### __WORK IN PROGRESS__
* (DutchmanNL) Proper value ranges for type light

### 0.1.2 (2021-03-02)
* (DutchmanNL) Type Fan added
Expand Down
32 changes: 29 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,28 @@ class Esphome extends utils.Adapter {
}

// Add unit to temperature states
if (stateName === `targetTemperature` || stateName === `targetTemperatureLow` || stateName === `targetTemperatureHigh`) {
if (stateName === `targetTemperature`
|| stateName === `targetTemperatureLow`
|| stateName === `targetTemperatureHigh`) {

unit = `°C`;

}

let writeValue = state[stateName];
// Add unit to temperature states
if (stateName === `brightness`
|| stateName === `blue`
|| stateName === `green`
|| stateName === `red`
|| stateName === `colorTemperature`) {

writeValue = state[stateName] * 100;

}

if (stateName !== 'key') {
await this.stateSetCreate(`${this.deviceInfo[host].deviceName}.${entity.type}.${entity.id}.${stateName}`, `value of ${entity.type}`, state[stateName], unit, writable);
await this.stateSetCreate(`${this.deviceInfo[host].deviceName}.${entity.type}.${entity.id}.${stateName}`, `value of ${entity.type}`, writeValue, unit, writable);
}
}
}
Expand Down Expand Up @@ -813,7 +830,16 @@ class Esphome extends utils.Adapter {
await client[deviceIP].connection.climateCommandService(this.deviceInfo[deviceIP][device[4]].states);

} else if (this.deviceInfo[deviceIP][device[4]].type === `Light`) {
this.deviceInfo[deviceIP][device[4]].states[device[5]] = state.val;
let writeValue = state.val;
// Add unit to temperature states
if (device[5] === `brightness`
|| device[5] === `blue`
|| device[5] === `green`
|| device[5] === `red`
|| device[5] === `colorTemperature`) {
writeValue = writevalue / 100;
}
this.deviceInfo[deviceIP][device[4]].states[device[5]] = writeValue ;
await client[deviceIP].connection.lightCommandService(this.deviceInfo[deviceIP][device[4]].states);
}
}
Expand Down

0 comments on commit 53217c9

Please sign in to comment.