Skip to content

Add configurable filter and state_filter to hui-image.#1423

Merged
balloob merged 6 commits into
home-assistant:masterfrom
jeradM:image-state-filters
Jul 10, 2018
Merged

Add configurable filter and state_filter to hui-image.#1423
balloob merged 6 commits into
home-assistant:masterfrom
jeradM:image-state-filters

Conversation

@jeradM
Copy link
Copy Markdown
Member

@jeradM jeradM commented Jul 8, 2018

Doesn't change any current cards, but will allow for more customization of images on picture-elements cards.

- type: image
  image: /local/living_room_light.png
  entity: light.living_room
  filter: brightness(80%)
  state_filter:
    'on': brightness(120%) saturate(1.5)
  style: 
    ...

fix home-assistant/ui-schema#89

@ghost ghost added the in progress label Jul 8, 2018
}

const stateImg = !unavailable ? this.stateImage[state.state] : this.stateImage.unavailable;
_updateStateFilter(state, unavailable) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we should call it stateObj. Isn't it redundant to have both, stateObj and unavailable? If it's unav. stateObj should be undefined?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah it's a little redundant, but I already checked that it was an object in _hassChanged() so I figured I would just pass that to the method as well to avoid checking it again before trying to access .state. I can just check it in _updateStateFilter() too if you prefer it that way

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest we get rid of the unavailable variable 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍 done

@@ -108,18 +110,35 @@ class HuiImage extends LocalizeMixin(PolymerElement) {

const state = hass.states[this.entity];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stateObj

@ghost ghost assigned c727 Jul 9, 2018
_imageSrc: null,
_error: true
});
this.$.image.classList.add('hidden');
Copy link
Copy Markdown
Member

@balloob balloob Jul 9, 2018

Choose a reason for hiding this comment

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

Should we hide it or render a broken image?

We could have a CSS like this:

background: grey url(https://thewindowsclub-thewindowsclubco.netdna-ssl.com/wp-content/uploads/2018/06/Broken-image-icon-in-Chrome.gif) center/30px no-repeat
height: 100px;

(we should obviously include the image in our repo)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, height should be the height of the last loaded image if available.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👍 I like this. I'm at work, but I'll try to get an update in this morning

_imageSrc: stateImg || this.image
});
const isOff = !stateObj || STATES_OFF.includes(stateObj.state);
this.$.image.style.filter = filter || (isOff && this._imageFallback && DEFAULT_FILTER) || '';
Copy link
Copy Markdown
Member

@balloob balloob Jul 9, 2018

Choose a reason for hiding this comment

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

This shit is getting so crazy, I feel like we need to add tests to make sure that all use cases are getting covered.

(out of scope for this PR)

@jeradM
Copy link
Copy Markdown
Member Author

jeradM commented Jul 9, 2018

The latest commit should fix home-assistant/ui-schema#89 as well. I'm not sure how to test turning off a camera, but it handles camera fetch promise rejection now

@balloob
Copy link
Copy Markdown
Member

balloob commented Jul 10, 2018

Just turn Home Assistant off while you keep the frontend open 😉

}

#brokenImage {
background: grey url('/static/images/broken_image.gif') center/30px no-repeat;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't include a 250px image if we are only rendering it at 30px. Resize it.

@balloob
Copy link
Copy Markdown
Member

balloob commented Jul 10, 2018

Updated image with one from material design icons:

image

@ghost ghost assigned balloob Jul 10, 2018
@balloob balloob merged commit 5df758c into home-assistant:master Jul 10, 2018
@ghost ghost removed the in progress label Jul 10, 2018
@jeradM jeradM deleted the image-state-filters branch July 10, 2018 13:31
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants