Skip to content
This repository has been archived by the owner on Nov 4, 2023. It is now read-only.

State #9

Closed
vassilis-panos opened this issue Jun 20, 2018 · 13 comments
Closed

State #9

vassilis-panos opened this issue Jun 20, 2018 · 13 comments

Comments

@vassilis-panos
Copy link

New state attribute is not working if I define the states mapping.
I think the previous behavior was better.

@resoai
Copy link
Collaborator

resoai commented Jun 20, 2018

You might be confusing state map with actual state i.e.

states: {on: 'Enabled', off: 'Disabled'}, // object of states map, used for mapping of states
//states: function (item, entity) {return entity.state}, // ot use function for getting state

and

//state: String || Function, // custom state of Tile

@Evgeny-
Copy link
Collaborator

Evgeny- commented Jun 20, 2018

@VPNMASTER Please show an example of tile config

@vassilis-panos
Copy link
Author

{ // Media center lamp
    position: [0, 1],
    width: 1,
    type: TYPES.LIGHT,
    id: 'light.media_center',
    title: 'Media center',
    subtitle: 'Lamps',
    states: {
        on: "On",
        off: "Off"
    },
    icons: {
        on: 'mdi-lamp',
        off: 'mdi-lamp'
    },
    state: switchPercents('brightness', 255, true),
    sliders: [brightnessSlider()],
}

@vassilis-panos
Copy link
Author

The state function works only If I remove the states mapping

@Evgeny-
Copy link
Collaborator

Evgeny- commented Jun 20, 2018

There was two separate elements that was able to show different states. Now it's only one, and states map have bigger priority. Though you still can handle in the state callback function.

Something like:

state: function (item, entity) {
   if('brightness' in entity.attributes) {
      return switchPercents('brightness', 255, true)(item, entity);
   }

   return ({on: "On", off: "Off"})[entity.state];
},

@vassilis-panos
Copy link
Author

Yes, finally I end up with doing this way.
But previous behavior where fall back to mapping when state (ex sub) is null was better.

@Evgeny-
Copy link
Collaborator

Evgeny- commented Jun 20, 2018

It's only look that way, in fact there was two elements and the second one overlap the first. So second one showed only when brightness was available, and the first one (on/off) was always in place.

@resoai
Copy link
Collaborator

resoai commented Jun 20, 2018

I think that sub was a bit confusing since you have been describing same element in two different places with two different names. You can easily create a helper function which would show % and on/off for all of your lights.

@Evgeny-
Copy link
Collaborator

Evgeny- commented Jun 20, 2018

So there's no problem to fallback into .state when states[entity.state] is null, but in fact it's never null in this case.

@vassilis-panos
Copy link
Author

Sorry, I meant the return of anonymous function and not the entity.state

@Evgeny-
Copy link
Collaborator

Evgeny- commented Jun 20, 2018

Oh yes, i got it. I'm looking into changing priorities from states->state to state->states., probably that should solve the problem, in this case.

@Evgeny-
Copy link
Collaborator

Evgeny- commented Jun 20, 2018

@VPNMASTER I've pushed new version, please try it out

@vassilis-panos
Copy link
Author

Thank you guys. Works like a charm

rchl pushed a commit that referenced this issue Mar 13, 2021
align changes in master
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants