Skip to content

Commit

Permalink
Better error handling. Fix #132
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Jun 30, 2020
1 parent 3dfaa1a commit 5026d7d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
6 changes: 5 additions & 1 deletion slider-entity-row.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class SliderEntityRow extends LitElement {

setConfig(config) {
this._config = config;
if(!config.entity)
throw new Error(`No entity specified.`);
const domain = config.entity.split('.')[0];
const ctrlClass = controllers[domain];
if(!ctrlClass)
Expand All @@ -52,6 +54,15 @@ class SliderEntityRow extends LitElement {
render() {
const c = this.ctrl;
c.hass = this.hass;
if (!c.stateObj)
return html`
<hui-warning>
${this.hass.localize("ui.panel.lovelace.warning.entity_not_found",
"entity",
this._config.entity
)}
</hui-warning>
`
const dir = this.hass.translationMetadata.translations[this.hass.language || "en"].isRTL ? "rtl" : "ltr";
const slider = html`
<ha-slider
Expand Down
2 changes: 1 addition & 1 deletion test/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_config:
demo:

lovelace:
mode: yaml
mode: storage
resources:
- url: /local/slider-entity-row.js
type: module
Expand Down
23 changes: 22 additions & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,28 @@ x-command: &x-command |
\"version\": 3
}
" > /config/.storage/onboarding &&
hass -c /config'
echo "
{
\"data\": {
\"items\": [
{
\"id\": \"1\",
\"type\": \"module\",
\"url\": \"/local/slider-entity-row.js\"
},
{
\"id\": \"2\",
\"type\": \"module\",
\"url\": \"/local/card-mod.js\"
}
]
},
\"key\": \"lovelace_resources\",
\"version\": 1
}
" > /config/.storage/lovelace_resources &&
hass -v -c /config'
version: '3.5'
services:
Expand Down
1 change: 1 addition & 0 deletions test/lovelace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ views:
- !include views/2_options.yaml
- !include views/3_attributes.yaml
- !include views/4_width.yaml
- !include views/5_errors.yaml
- title: test
cards:
- type: picture-elements
Expand Down
22 changes: 22 additions & 0 deletions test/views/5_errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
x-anchors:
desc: &desc
type: markdown
style: |
code {
font-size: 8pt;
line-height: normal;
white-space: pre-wrap;
}
title: Errors
cards:
- type: entities
entities:
- type: section
label: No entity
- type: custom:slider-entity-row

- type: section
label: Unknown entity
- type: custom:slider-entity-row
entity: light.no_light

0 comments on commit 5026d7d

Please sign in to comment.