Skip to content

Commit

Permalink
Add attributes. Fix #48. Fix #38
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Aug 5, 2019
1 parent 9b36cf2 commit a4edb45
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 33 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Currenly supported entity domains:
- `min: <value>` - Set minimum value of slider
- `max: <value>` - Set maximum value of slider
- `step: <value>` - Set step size of slider
- `attribute: <value>` - Select which attribute the slider should control

```yaml
type: entities
Expand Down Expand Up @@ -76,5 +77,23 @@ entities:

![options](https://user-images.githubusercontent.com/1299821/59467902-19dd8380-8e31-11e9-9173-97c9b6be3179.png)

#### Attributes
Currently, the following attribute settings are supported.

**For `light` domain:**

- `brightness` - default
- `color_temp`
- `hue`
- `saturation`
- `red`
- `green`
- `blue`

**For `cover` domain:**

- `position` - default
- `tilt`

---
<a href="https://www.buymeacoffee.com/uqD6KHCdJ" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/white_img.png" alt="Buy Me A Coffee" style="height: auto !important;width: auto !important;" ></a>
16 changes: 8 additions & 8 deletions slider-entity-row.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 50 additions & 14 deletions src/cover-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,72 @@ import {Controller} from "./controller.js";

export class CoverController extends Controller {

get attribute() {
return this._config.attribute || "position";
}

get _value() {
return this.stateObj.state === "open"
? this.stateObj.attributes.current_position
: 0;
switch (this.attribute) {
case "position":
return this.stateObj.state === "open"
? this.stateObj.attributes.current_position
: 0;
case "tilt":
return this.stateObj.attributes.current_tilt_position;
default:
return 0;
}
}

set _value(value) {
this._hass.callService("cover", "set_cover_position", {
entity_id: this.stateObj.entity_id,
position: value,
});
switch (this.attribute) {
case "position":
this._hass.callService("cover", "set_cover_position", {
entity_id: this.stateObj.entity_id,
position: value,
});
break;
case "tilt":
this._hass.callService("cover", "set_cover_tilt_position", {
entity_id: this.stateObj.entity_id,
tilt_position: value,
});
break;
default:
}

}

get string() {
if (!this.hasSlider)
return "";
if (this.stateObj.state === "closed")
return this._hass.localize("state.cover.closed");
return `${this.value} %`
switch (this.attribute) {
case "position":
if (this.stateObj.state === "closed")
return this._hass.localize("state.cover.closed");
return `${this.value} %`
case "tilt":
return this.value;
}
}

get hasToggle() {
return false;
}

get hasSlider() {
if ("current_position" in this.stateObj.attributes) return true;
if (("supported_features" in this.stateObj.attributes) &&
(this.stateObj.attributes.supported_features & 4)) return true;
return false;
switch (this.attribute) {
case "position":
if ("current_position" in this.stateObj.attributes) return true;
if (("supported_features" in this.stateObj.attributes) &&
(this.stateObj.attributes.supported_features & 4)) return true;
case "tilt":
if ("current_tilt_position" in this.stateObj.attributes) return true;
if (("supported_features" in this.stateObj.attributes) &&
(this.stateObj.attributes.supported_features & 128)) return true;
default:
return false;
}
}

get _step() {
Expand Down
Loading

0 comments on commit a4edb45

Please sign in to comment.