Skip to content

Commit

Permalink
Merge pull request #28 from artem-sedykh/dev
Browse files Browse the repository at this point in the history
fix List ordering #27
  • Loading branch information
artem-sedykh authored Jun 16, 2020
2 parents 55296c8 + 5e1e936 commit bbdcb20
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 14 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Please ⭐️ this repo if you find it useful

```yaml
resources:
- url: /local/mini-climate-card-bundle.js?v=1.2.4
- url: /local/mini-climate-card-bundle.js?v=1.2.5
type: module
```
Expand All @@ -33,14 +33,14 @@ Please ⭐️ this repo if you find it useful
2. Grab `mini-climate-card-bundle.js`

```console
$ wget https://github.com/artem-sedykh/mini-climate-card/releases/download/v1.2.4/mini-climate-card-bundle.js
$ wget https://github.com/artem-sedykh/mini-climate-card/releases/download/v1.2.5/mini-climate-card-bundle.js
```

3. Add a reference to `mini-climate-card-bundle.js` inside your `ui-lovelace.yaml`.

```yaml
resources:
- url: /local/mini-climate-card-bundle.js?v=1.2.4
- url: /local/mini-climate-card-bundle.js?v=1.2.5
type: module
```

Expand All @@ -53,7 +53,7 @@ Please ⭐️ this repo if you find it useful

```yaml
resources:
- url: /local/mini-climate-card-bundle.js?v=1.2.4
- url: /local/mini-climate-card-bundle.js?v=1.2.5
type: module
```

Expand Down Expand Up @@ -114,6 +114,7 @@ Please ⭐️ this repo if you find it useful
| hvac_mode: `source:item` | object | optional | v1.0.1 | `item` - mode name e.g. cool, heat, off, etc.
| hvac_mode: `source:item:icon` | string | optional | v1.0.1 | Specify a custom icon from any of the available mdi icons.
| hvac_mode: `source:item:name` | string | optional | v1.0.1 | Display name.
| hvac_mode: `source:item:order` | number | optional | v1.2.5 | sort order.
| **fan_mode** | object | optional | v1.0.1 | fan operation for climate device. [fan_mode examples](#fan_mode)
| fan_mode: `icon` | string | optional | v1.0.1 | Specify a custom icon from any of the available mdi icons.
| fan_mode: `order` | number | optional | v1.0.1 | sort order, default value `0`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mini-climate-card",
"version": "v1.2.4",
"version": "v1.2.5",
"description": "a/c card for Home Assistant Lovelace UI",
"keywords": [
"home-assistant",
Expand Down
23 changes: 23 additions & 0 deletions release_notes/v1.2.5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## v1.2.5
[![Downloads](https://img.shields.io/github/downloads/artem-sedykh/mini-climate-card/v1.2.5/total.svg)](https://github.com/artem-sedykh/mini-climate-card/releases/tag/v1.2.5)

### ADDED

- sort order for dropdown

```yaml
- type: custom:mini-climate
entity: climate.dahatsu
name: Кондиционер
hvac_mode:
source:
'off':
name: 'off'
order: 4
heat:
name: heat
order: 2
cool:
name: cool
order: 1
```
14 changes: 11 additions & 3 deletions src/models/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,17 @@ export default class ButtonObject {

get source() {
const { functions } = this.config;
const source = Object.entries(this.config.source || {})
.filter(s => s[0] !== '__filter')
.map(s => ({ id: s[0], name: s[1] }));
let source = Object.entries(this.config.source || {})
.filter(([key]) => key !== '__filter')
.map(([key, value]) => {
if (typeof value === 'object') {
return { id: key, ...value || {} };
}
return { id: key, name: value };
});

if (source.some(s => 'order' in s))
source = source.sort((a, b) => ((a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0)));

if (functions.source && functions.source.filter) {
return functions.source.filter(source, this.state, this.entity,
Expand Down
15 changes: 9 additions & 6 deletions src/models/hvac-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,18 @@ export default class HvacModeObject {

get source() {
const { functions } = this.config;
const source = Object.entries(this.config.source || {})
.filter(s => s[0] !== '__filter')
.map((s) => {
if (typeof s[1] === 'object') {
return { id: s[0], ...s[1] || {} };
let source = Object.entries(this.config.source || {})
.filter(([key]) => key !== '__filter')
.map(([key, value]) => {
if (typeof value === 'object') {
return { id: key, ...value || {} };
}
return { id: s[0], name: s[1] };
return { id: key, name: value };
});

if (source.some(s => 'order' in s))
source = source.sort((a, b) => ((a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0)));

if (functions.source && functions.source.filter) {
return functions.source.filter(source, this.state, this.entity, this.climate.entity);
}
Expand Down

0 comments on commit bbdcb20

Please sign in to comment.