Skip to content

Commit

Permalink
Added support for dimming via core:LightIntensityState
Browse files Browse the repository at this point in the history
  • Loading branch information
Excodibur committed Aug 26, 2022
1 parent c8f175f commit 97a8c5f
Show file tree
Hide file tree
Showing 8 changed files with 9,362 additions and 195 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
Placeholder for the next version (add instead of version-number-headline below):
## **WORK IN PROGRESS**
-->
## 0.8.0 (2022-08-26)
- Added support for dimming via core:LightIntensityState

## 0.7.2 (2022-06-15)
- Fix switching between local and online api

Expand Down
358 changes: 185 additions & 173 deletions io-package.json

Large diffs are not rendered by default.

30 changes: 27 additions & 3 deletions lib/tahoma.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ Tahoma.prototype.getCreateStateOptions4Widget = function (widget) {
"role": "sensor"
};

case "DimmerLight":
return {
"role": "light.dimmer",
"features": {
"intensity": true
}
};
default:
return {
"role": "state"
Expand Down Expand Up @@ -253,6 +260,16 @@ Tahoma.prototype.getCreateStateOptions4State = function (widget, stateName) {
"write": true, // mandatory, default true
"role": "switch" // mandatory
};
} else if (stateName === "core:LightIntensityState") {
return {
"type": "number", // optional, default "number"
"read": true, // mandatory, default true
"write": true, // mandatory, default true
"min": 0, // optional, default 0
"max": 100, // optional, default 100
"unit": "W", // optional, default W
"role": "level.dimmer" // mandatory
};
} else {
return {
"read": true,
Expand Down Expand Up @@ -1299,11 +1316,11 @@ Tahoma.prototype.updateDeviceState = function (event) {
if (object.type === "channel") {
try {
let subStates;
if(typeof value === "object") {
if (typeof value === "object")
subStates = value;
} else {
else
subStates = JSON.parse(value);
}

const channelPath = key;
for (const [attrName, attrValue] of Object.entries(subStates)) {
controller.ackStateValues[channelPath + "." + attrName] = attrValue;
Expand Down Expand Up @@ -1382,6 +1399,9 @@ Tahoma.prototype.onApplyChange = function (attribute, id, value, slow) {
} else if (attribute === "onoff") {
commandName = "setOnOff";
stateName = "core:OnOffState";
} else if (attribute === "intensity") {
commandName = "setIntensity";
stateName = "core:LightIntensityState";
}

controller.context.getState(id.substr(0, id.indexOf(".states.")) + ".deviceURL", function (err, state) {
Expand Down Expand Up @@ -1547,6 +1567,10 @@ Tahoma.prototype.onOnOffStateChange = function (id, value) {
return controller.onApplyChange("onoff", id, value);
};

Tahoma.prototype.onIntensityStateChange = function (id, value) {
return controller.onApplyChange("intensity", id, value);
};

Tahoma.prototype.onExecuteCommand = function (id) {
controller.context.getState(id.substr(0, id.indexOf(".commands.")) + ".oid", function (err, state) {
if (!err && state) {
Expand Down
2 changes: 2 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ function processStateChange (id, value) {
controller.onSetOrientation(id, value);
else if (id.match(/^actionGroups.*\.commands\.execute/) && value)
controller.onExecuteCommand(id, value);
else if (id.match(/^devices.*\.states\.core:LightIntensityState$/))
controller.onIntensityStateChange(id, value);
else if (id.match(/^devices.*\.commands\./) && value) {
if (id.endsWith(":slow")) {
adapter.log.debug("Triggered command with slow mode: " + id);
Expand Down
Loading

0 comments on commit 97a8c5f

Please sign in to comment.