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

Feature request: functions for list values #55

Closed
rogersmj opened this issue Jun 30, 2018 · 7 comments
Closed

Feature request: functions for list values #55

rogersmj opened this issue Jun 30, 2018 · 7 comments

Comments

@rogersmj
Copy link
Contributor

I want to be able to render other text in the list for sensors that have "on/off" state. For example:

{
                           title: 'Garage (1)',
                           icon: 'mdi-garage',
                           value: function() {
                             var val='&binary_sensor.garage_single_bay.state';
                             if(val=="On") {
                               return "Open";
                             } else {
                               return "Closed";
                             }
                           }
                        }

This doesn't seem to work right now, it just tries to render the function as a string:

image

Having this would be a very powerful addition to lists.

@resoai
Copy link
Collaborator

resoai commented Jun 30, 2018

Filter already exists but you need to define in tile, not in each list item

@resoai resoai closed this as completed Jul 3, 2018
@Evgeny- Evgeny- reopened this Jul 4, 2018
@Evgeny-
Copy link
Collaborator

Evgeny- commented Jul 4, 2018

Filters aren't great solution. Probably we should think about make most of properties both functions and strings.

@Evgeny-
Copy link
Collaborator

Evgeny- commented Jul 4, 2018

Fields in lists now can be used as functions, every function called with context {states, $scope} and has argument tile (that you've proveided in config).

@Evgeny- Evgeny- closed this as completed Jul 5, 2018
@stewface
Copy link

Could someone explain to me how to code this up to get it working?

`{
position: [1, 1],
width: 2,
type: TYPES.TEXT_LIST,
id: {}, // using empty object for an unknown id
states: {
on: "Open",
off: "Closed"

},

                 list: [
                 {
                      title: 'Front Door',
                  icon: 'mdi-glassdoor',
                      value: '&binary_sensor.door_window_sensor_158d000153a7ed.state',
                      **states: {
                         on: "Open",
                         off: "Closed"**
                      },
                 },`

Neither position seems to be correct for me (well they both dont work)

@resoai
Copy link
Collaborator

resoai commented Oct 31, 2018

Text list tile has nothing to do with states. Use anon function to format value however you like:

value: function() {
   var val = this.parseFieldValue('&binary_sensor.door_window_sensor_158d000153a7ed.state');
   return val == 'on' ? 'Open' : 'Closed';
}

@stewface
Copy link

stewface commented Nov 4, 2018

Awesome - thank you!! :)

Working perfectly.

@markwoitaszek
Copy link

Thank you so much for posting this! Been trying to figure it out for hours.

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

4 participants