Skip to content

Commit 5026d7d

Browse files
committed
Better error handling. Fix #132
1 parent 3dfaa1a commit 5026d7d

File tree

6 files changed

+62
-3
lines changed

6 files changed

+62
-3
lines changed

slider-entity-row.js

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class SliderEntityRow extends LitElement {
2929

3030
setConfig(config) {
3131
this._config = config;
32+
if(!config.entity)
33+
throw new Error(`No entity specified.`);
3234
const domain = config.entity.split('.')[0];
3335
const ctrlClass = controllers[domain];
3436
if(!ctrlClass)
@@ -52,6 +54,15 @@ class SliderEntityRow extends LitElement {
5254
render() {
5355
const c = this.ctrl;
5456
c.hass = this.hass;
57+
if (!c.stateObj)
58+
return html`
59+
<hui-warning>
60+
${this.hass.localize("ui.panel.lovelace.warning.entity_not_found",
61+
"entity",
62+
this._config.entity
63+
)}
64+
</hui-warning>
65+
`
5566
const dir = this.hass.translationMetadata.translations[this.hass.language || "en"].isRTL ? "rtl" : "ltr";
5667
const slider = html`
5768
<ha-slider

test/configuration.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_config:
33
demo:
44

55
lovelace:
6-
mode: yaml
6+
mode: storage
77
resources:
88
- url: /local/slider-entity-row.js
99
type: module

test/docker-compose.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,28 @@ x-command: &x-command |
4141
\"version\": 3
4242
}
4343
" > /config/.storage/onboarding &&
44-
hass -c /config'
44+
echo "
45+
{
46+
\"data\": {
47+
\"items\": [
48+
{
49+
\"id\": \"1\",
50+
\"type\": \"module\",
51+
\"url\": \"/local/slider-entity-row.js\"
52+
},
53+
{
54+
\"id\": \"2\",
55+
\"type\": \"module\",
56+
\"url\": \"/local/card-mod.js\"
57+
}
58+
]
59+
},
60+
\"key\": \"lovelace_resources\",
61+
\"version\": 1
62+
}
63+
" > /config/.storage/lovelace_resources &&
64+
65+
hass -v -c /config'
4566
4667
version: '3.5'
4768
services:

test/lovelace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ views:
55
- !include views/2_options.yaml
66
- !include views/3_attributes.yaml
77
- !include views/4_width.yaml
8+
- !include views/5_errors.yaml
89
- title: test
910
cards:
1011
- type: picture-elements

test/views/5_errors.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
x-anchors:
2+
desc: &desc
3+
type: markdown
4+
style: |
5+
code {
6+
font-size: 8pt;
7+
line-height: normal;
8+
white-space: pre-wrap;
9+
}
10+
11+
title: Errors
12+
cards:
13+
- type: entities
14+
entities:
15+
- type: section
16+
label: No entity
17+
- type: custom:slider-entity-row
18+
19+
- type: section
20+
label: Unknown entity
21+
- type: custom:slider-entity-row
22+
entity: light.no_light

0 commit comments

Comments
 (0)