Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[items] Refactor metadata & itemchannllink APIs #212

Merged
merged 16 commits into from
Dec 30, 2022

Conversation

florian-h05
Copy link
Contributor

@florian-h05 florian-h05 commented Dec 29, 2022

Fixes #189.

Description

This PR completely refactors the metadata and the itemchannellink APIs.
Their old versions have been removed (since metadata was unable to support configuration, I'm not sure how many even used it).

The new metadata API is available under the items namespace and is able to add and change metadata configuration as well.
itemchannellink got a few internal improvements and a renaming.

To Do

  • Update CHANGELOG

Testing

The following script tests all methods of these APIs:

// replaceMetadata and replaceItemChannelLink are used inside the replaceItem method
items.replaceItem({
  type: 'String',
  name: 'Hallway_Light',
  label: 'Hallway Light',
  category: 'light',
  groups: ['Hallway', 'Light'],
  tags: ['Lightbulb'],
  channels: {
    'binding:thing:device:hallway#light': {},
    'binding:thing:device:livingroom#light': { 
      profile: 'system:follow' 
    }
  },
  metadata: {
    expire: '10m,command=1',
    stateDescription: {
      config: {
        pattern: '%d%%',
        options: '1=Red, 2=Green, 3=Blue'
      }
    }
  }
});

// getMetadata
console.log('Metadata expire = ' + JSON.stringify(items.getItem('Hallway_Light').getMetadata('expire')));
console.log('Metadata stateDescription configuration = ' + items.getItem('Hallway_Light').getMetadata('stateDescription').configuration);

// removeMetadata
console.warn('Removing metadata expire ...')
items.getItem('Hallway_Light').removeMetadata('expire');
console.log('Metadata expire = ' + items.getItem('Hallway_Light').getMetadata('expire'));

// getItemChannelLink
console.log(items.metadata.itemchannellink.getItemChannelLink('Hallway_Light', 'binding:thing:device:livingroom#light'))
console.log(items.metadata.itemchannellink.getItemChannelLink('Hallway_Light', 'binding:thing:device:livingroom#light').configuration)


// removeItemChannelLink
items.metadata.itemchannellink.removeItemChannelLink('Hallway_Light', 'binding:thing:device:livingroom#light');
console.log(items.metadata.itemchannellink.getItemChannelLink('Hallway_Light', 'binding:thing:device:livingroom#light'))

@florian-h05 florian-h05 added enhancement New feature or request breaking change API breaking changes labels Dec 29, 2022
@florian-h05 florian-h05 added this to the to be released milestone Dec 29, 2022
@florian-h05 florian-h05 changed the title [items] Refactor metadata & itemchannllink [items] Refactor metadata & itemchannllink APIs Dec 29, 2022
@florian-h05 florian-h05 force-pushed the metadata-refactoring branch 2 times, most recently from 5c098d5 to ab1ecfe Compare December 29, 2022 20:50
@florian-h05
Copy link
Contributor Author

@rkoshak Ping.

@florian-h05 florian-h05 modified the milestones: 3.2.0, to be released Dec 30, 2022
Copy link
Contributor

@digitaldan digitaldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Their old versions have been removed (since metadata was unable to support configuration, I'm not sure how many even used it).

So i poked around a little on this, i think the few that were using item links, used the native Java proxy objects and did not use this library, so i think its probably a very small population if any .

I had only a few small nits, other wise LGTM

@florian-h05
Copy link
Contributor Author

@digitaldan I have addressed your review, can you please have a look at the changes?

i think its probably a very small population if any .

I thing the same, but I'll label it as breaking to make sure that no one is suprised

Copy link
Contributor

@digitaldan digitaldan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had two more code style changes recommendations. Feel free to merge either way. Thanks!

florian-h05 and others added 16 commits December 30, 2022 18:30
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

Co-authored-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>

Co-authored-by: Dan Cunningham <dan@digitaldan.com>
Signed-off-by: Florian Hotze <florianh_dev@icloud.com>
@florian-h05 florian-h05 merged commit eccf2d4 into openhab:main Dec 30, 2022
@florian-h05 florian-h05 deleted the metadata-refactoring branch December 30, 2022 17:34
@rkoshak
Copy link
Contributor

rkoshak commented Dec 30, 2022

Sorry I missed the ping. It all looks as I would expect from the metadata side (I never messed with channel links in rules so don't have much to say there.

@proggprod
Copy link

Been playing around with this. Would be nice if I could remove all channel links or metadata by excluding the name or some other wildcard. Sometimes I don't want to specify the name or channel link, I just want to remove/replace.

@florian-h05
Copy link
Contributor Author

IIRC, openHAB Core provides that possibility, so I could add this to the library as well. Can you please open an issue and describe your feature request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change API breaking changes enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[metadata] Add support for configuration
5 participants