iobroker-community-adapters / ioBroker.openhab

Connect ioBroker with openHAB
MIT License
13 stars 3 forks source link

Parsing of OH type Number not complete at startup (incomplete types.js) #10

Closed Schluesselmeister closed 6 years ago

Schluesselmeister commented 6 years ago

The object of OH are parsed at startup of the adapter. If an object of type "Number" is parsed, then the result is not complete as e.g. the item.label is not set. Furthermore the categories provided by OH start with a capital letter. With a modification as shown below the labels and roles are set correctly. I have added the "humidity" category also.

Regards, Sven

Number definition (types.js)

        var data = {
            name: item.label,
            type: 'number',
            read: true,
            write: false
        };
        if (item.stateDescription) {
            if (item.stateDescription.pattern && item.stateDescription.pattern.indexOf('°C') !== -1) {
                data.unit = '°C';
            }
            if (item.stateDescription.pattern && item.stateDescription.pattern.indexOf('°F') !== -1) {
                data.unit = '°F';
            }

            if ( (item.category === 'temperature' || item.category === 'Temperature') && item.stateDescription.readOnly === false) {
                data.role = 'level.temperature';
                data.write = true;
            } else if (item.category === 'temperature' || item.category === 'Temperature') {
                data.role = 'value.temperature';
            } else if (item.category === 'humidity' || item.category === 'Humidity') {
                data.role = 'value.humidity';
            }
        } else {
            if (item.category === 'temperature' || item.category === 'Temperature') {
                data.role = 'value.temperature';
            } else if (item.category === 'humidity' || item.category === 'Humidity') {
                data.role = 'value.humidity';
            }
        }
Schluesselmeister commented 6 years ago

Due to the other open issue #5, I have modified the types.h again. It is not complete, as e.g. a switch might also be "readonly". But that is the actual version of the file I have.

types.zip

Regards, Sven

Schluesselmeister commented 6 years ago

Using the last version, which I have attached above, the SetPoint of a Thermostat can also be set. This should solve #5.

I will create a corresponding pull request.

Regards, Sven

Apollon77 commented 6 years ago

Great!

Schluesselmeister commented 6 years ago

Modifications have been merged into the master branch,