Skip to content

Commit

Permalink
Merge pull request #87 from twrecked/config-tidy
Browse files Browse the repository at this point in the history
Tidy Config.
  • Loading branch information
twrecked authored Feb 25, 2021
2 parents 909a672 + 8349c89 commit d00b857
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 104 deletions.
62 changes: 26 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,32 +164,35 @@ entities:

| Name | Type | Required | Supported Values |
|------------|------|----------|---------------------------------------------|
| global | list | No | active, muted, numeric, square |
| global | list | No | active, muted, square, blended |

These are the options that determine the overall behaviour of the card.
- `active`; for multi camera cards, the image will change to the most recently
updated camera
- `muted`; start in a muted state, mute state is remember across recordings
and streams
- `numeric`; show the library count as a number, works up to `9`, after which
`9+` is shown
- `square`; use a square image; useful for Arlo Video Doorbells; this affects
the library view as well.
- `active`; for multi camera cards, the image will change to the most recently
updated camera
- `muted`; start in a muted state, mute state is remember across recordings
and streams
- `square`; use a square image; useful for Arlo Video Doorbells; this affects
the library view as well.
- `blended`; for multi camera cards; the library view will display all camera
recordings spliced together


#### Image Options

| Name | Type | Required | Supported Values |
|------------|------|----------|---------------------------------------------|
| image_view | list | No | start-stream, start-recording, direct |
| Name | Type | Required | Supported Values |
|------------|------|----------|-----------------------------------------------------|
| image_view | list | No | start-stream, start-recording, direct, modal, smart |

These are the options that determine the overall behaviour of the card when
showing the image view.
- `start-stream`; the card will start streaming when opened
- `start-recording`; _not implemented yet_, the card will play recording when
finished
- `direct`; when streaming the card will access Arlo directly rather than go
through Home Assistant
- `start-stream`; the card will start streaming when opened
- `start-recording`; _not implemented yet_, the card will play recording when
finished
- `direct`; when streaming the card will access Arlo directly rather than go
through Home Assistant
- `modal`; open the recording or stream in a modal window
- `smart`; open the recording or stream in a modal window on a desktop
machine, show inline otherwise.


| Name | Type | Required | Supported Values |
Expand Down Expand Up @@ -246,12 +249,9 @@ binary_sensor:

| Name | Type | Required | Supported Values |
|-------------|------|----------|---------------------------------|
| image_click | list | No | modal, smart, stream, recording |
| image_click | list | No | stream, recording |

This option determines what happens when you click the image
- `modal`; open the recording or stream in a modal window
- `smart`; open the recording or stream in a modal window on a desktop machine,
shown in line otherwise.
- `stream`; start a live stream
- `recording`; play the last recording

Expand All @@ -264,24 +264,16 @@ snapshot image doesn't update all the time try adding extra time outs.

#### Library Options

| Name | Type | Required | Supported Values |
|--------------|------|----------|------------------------------------|
| library_view | list | No | blended, start-recording, download |
| Name | Type | Required | Supported Values |
|--------------|------|----------|--------------------------------------------------|
| library_view | list | No | blended, start-recording, download, modal, smart |

This option determines the overall behaviour of the card when showing the
library view.
- `blended`; for multi camera cards; the library view will display all camera
recordings spliced together
- `start-recording`; _not implemented yet_, automatically show the recording when
finished.
- `download`; show an icon to download the video when the mouse hovers over
the recording thumbnail

| Name | Type | Required | Supported Values |
|---------------|------|----------|---------------------------------|
| library_click | list | No | modal, smart |

This option determine what happens when you click the image
- `modal`; open the recording or stream in a modal window
- `smart`; open the recording or stream in a modal window on a desktop
machine, show inline otherwise.
Expand Down Expand Up @@ -450,9 +442,8 @@ entities:
name: front door
- entity: camera.aarlo_front_camera
name: front
global: active
global: active,blended
image_view: direct
library_view: blended
image_top: 'name,status'
image_bottom: 'motion,library,stream,snapshot,battery'
image_click: 'recordings'
Expand All @@ -478,9 +469,8 @@ entities:
name: back door
door: binary_sensor.back_door
door_lock: lock.back_door_lock
global: active
global: active,blended
image_view: direct
library_view: blended
image_top: 'name,status'
image_bottom: 'motion,library,play,snapshot,battery'
image_click: 'recordings'
Expand Down
141 changes: 73 additions & 68 deletions dist/hass-aarlo.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,13 +907,13 @@ class AarloGlance extends LitElement {
( captured === "0" ? "" : `${captured} ${this._i.status.captured_something} ${last}, ` ) +
this._i.status.library_open,
captured !== "0" ? 'on' : '',
this.gc.numeric ? 'mdi:numeric-' + (captured > 9 ? "9-plus" : captured) + '-box' : 'mdi:file-video'
this.cc.numericView ? 'mdi:numeric-' + (captured > 9 ? "9-plus" : captured) + '-box' : 'mdi:file-video'
)
} else {
this.cs.details.library = _tsi(
`${this._i.status.library}: ${this._i.status.library_empty}`,
'off',
this.gc.numeric ? 'mdi:numeric-0-box' : 'mdi:file-video-outline'
this.cc.numericView ? 'mdi:numeric-0-box' : 'mdi:file-video-outline'
)
}

Expand Down Expand Up @@ -1001,6 +1001,15 @@ class AarloGlance extends LitElement {
'mdi:lightbulb'
)
}
if(this.cc.light2Id) {
const lightState = this._getState(this.cc.light2Id, 'off');
const is_on = lightState.state === 'on'
this.cs.details.light2 = _tsi(
`${lightState.attributes.friendly_name}: ` + (is_on ? this._i.status.light_on : this._i.status.light_off),
is_on ? 'on' : '',
'mdi:lightbulb'
)
}
}

updateStatuses() {
Expand Down Expand Up @@ -1060,34 +1069,20 @@ class AarloGlance extends LitElement {

// active camera mode
activeView: (_includes( config.global, "active" ) ||
_includes( config.image_view, "active" )),
_includes( config.image_view, "active" )),

// initial state is muted
isMuted: _includes( config.global, "muted" ),
// numeric icons for library
numeric: _includes( config.global, 'numeric' ),

// aspect ratio
aspectRatio: (_includes(config.global, 'square') ||
_includes(config.image_view, 'square')) ? '1x1' : '16x9',
_includes(config.image_view, 'square')) ? '1x1' : '16x9',
aspectRatioMultiplier: (_includes(config.global, 'square') ||
_includes(config.image_view, 'square')) ? 1 : 0.5625,

// auto play
autoPlay: _includes( config.image_view, "autoplay" ) ||
_includes( config.image_view, "start-stream" ) ||
_value( config.auto_play, false ),
// auto play recording
autoPlayRecording: _includes( config.image_view, "start-recording" ),
// stream directly from Arlo
playDirect: _includes( config.image_view, "direct" ) ||
_value( config.play_direct, false ),
_includes(config.image_view, 'square')) ? 1 : 0.5625,

// blended library
blendedMode: _includes( config.library_view, "blended" ),
// auto play recording when finished
libraryAutoPlay: _includes( config.library_view, "autoplay" ) ||
_includes( config.image_view, "start-recording" ),
// download videos?
libraryDownload: _includes( config.library_view, "download" ),
blendedMode: _includes(config.global, 'blended') ||
_includes( config.library_view, "blended" ),

// modal window multiplier
modalMultiplier: _value_float( config.modal_multiplier, 0.8 ),
Expand Down Expand Up @@ -1195,25 +1190,21 @@ class AarloGlance extends LitElement {

// What happens when we click on image
const image_click = config.image_click ? config.image_click : ""
cc.imageClickStream = image_click.includes("live") ||
image_click.includes("play") ||
image_click.includes("stream")
cc.imageClickModal = image_click.includes("modal")
cc.imageClickSmart = image_click.includes("smart")
cc.imageAutoPlay = image_click.includes("autoplay")
cc.directPlay = image_click.includes("direct") || _value( config.play_direct, false )
cc.modalPlayer = image_click.includes("modal")
cc.smartPlayer = image_click.includes("smart")
cc.autoPlay = image_click.includes("autoplay") || _value( config.auto_play, false )

cc.playStream = image_click.includes("live") ||
image_click.includes("play") ||
image_click.includes("stream")

// snapshot updates
cc.snapshotTimeouts = config.snapshot_retry ? config.snapshot_retry : [ 2, 5 ]

// modal window multiplier
cc.modalMultiplier = config.modal_multiplier ? parseFloat(config.modal_multiplier) : 0.8;

// stream directly from Arlo
cc.playDirectFromArlo = config.play_direct ? config.play_direct : false;

// auto play
cc.autoPlay = config.auto_play ? config.auto_play : false

// camera and sensors
cc.id = config.camera_id ? config.camera_id : 'camera.' + prefix + camera;
cc.motionId = config.motion_id ? config.motion_id : 'binary_sensor.' + prefix + 'motion_' + camera;
Expand Down Expand Up @@ -1255,7 +1246,6 @@ class AarloGlance extends LitElement {
return
}
const camera = entity.replace( 'camera.aarlo_','' )
const prefix = "aarlo_"

let cc = {}

Expand All @@ -1266,38 +1256,44 @@ class AarloGlance extends LitElement {
cc.image_top = config.image_top
cc.image_bottom = config.image_bottom

// What does clicking the image do?
const image_click = _array( config.image_click )
cc.imageClickModal = image_click.includes("modal")
cc.imageClickSmart = image_click.includes("smart")
cc.imageClickStream = image_click.includes("stream")
// How do we display recordings or stream?
cc.directPlay = _includes(config.image_view, "direct")
cc.modalPlayer = _includes(config.image_view, "modal")
cc.numericView = _includes(config.image_view, 'numeric')
cc.smartPlayer = _includes(config.image_view, "smart")
cc.autoPlay = _includes(config.image_view, 'start-stream')
cc.autoPlayRecording = _includes(config.image_view, 'start-recording')

// Does clicking show the live stream or last recording?
cc.playStream = _includes( config.image_click, "stream")

// snapshot updates
cc.snapshotTimeouts = _array( config.snapshot_retry, [ 2, 5 ] )

// camera and sensors
cc.id = config.camera_id ? config.camera_id : 'camera.' + prefix + camera;
cc.motionId = config.motion_id ? config.motion_id : 'binary_sensor.' + prefix + 'motion_' + camera;
cc.soundId = config.sound_id ? config.sound_id : 'binary_sensor.' + prefix + 'sound_' + camera;
cc.batteryId = config.battery_id ? config.battery_id : 'sensor.' + prefix + 'battery_level_' + camera;
cc.signalId = config.signal_id ? config.signal_id : 'sensor.' + prefix + 'signal_strength_' + camera;
cc.capturedTodayId = config.capture_id ? config.capture_id : 'sensor.' + prefix + 'captured_today_' + camera;
cc.lastCaptureId = config.last_id ? config.last_id : 'sensor.' + prefix + 'last_' + camera;
cc.id = _value(config.camera_id, `camera.aarlo_${camera}`)
cc.motionId = _value(config.motion_id, `binary_sensor.aarlo_motion_${camera}`)
cc.soundId = _value(config.sound_id, `binary_sensor.aarlo_sound_${camera}`)
cc.batteryId = _value(config.battery_id, `sensor.aarlo_battery_level_${camera}`)
cc.signalId = _value(config.signal_id, `sensor.aarlo_signal_strength_${camera}`)
cc.capturedTodayId = _value(config.capture_id, `sensor.aarlo_captured_today_${camera}`)
cc.lastCaptureId = _value(config.last_id, `sensor.aarlo_last_${camera}`)

// door definition
cc.doorId = config.door ? config.door: null;
cc.doorBellId = config.door_bell ? config.door_bell : null;
cc.doorBellMuteId = config.door_bell_mute ? config.door_bell_mute : null;
cc.doorLockId = config.door_lock ? config.door_lock : null;
cc.doorId = _value(config.door)
cc.doorBellId = _value(config.door_bell)
cc.doorBellMuteId = _value(config.door_bell_mute)
cc.doorLockId = _value(config.door_lock)

// door2 definition
cc.door2Id = config.door2 ? config.door2: null;
cc.door2BellId = config.door2_bell ? config.door2_bell : null;
cc.door2BellMuteId = config.door2_bell_mute ? config.door2_bell_mute : null;
cc.door2LockId = config.door2_lock ? config.door2_lock : null;
cc.door2Id = _value(config.door2)
cc.door2BellId = _value(config.door2_bell)
cc.door2BellMuteId = _value(config.door2_bell_mute)
cc.door2LockId = _value(config.door2_lock)

// light definition
cc.lightId = config.light ? config.light: null;
// light definitions
cc.lightId = _value(config.light)
cc.light2Id = _value(config.light2)

return cc
}
Expand Down Expand Up @@ -1328,8 +1324,10 @@ class AarloGlance extends LitElement {

return {
// What to when video clicked
imageClickModal: _includes( config.library_click, "modal"),
imageClickSmart: _includes( config.library_click, "smart" ),
download: _includes(config.library_view, "download"),
modalPlayer: _includes(config.library_view, "modal"),
smartPlayer: _includes(config.library_view, "smart"),
autoPlayRecording: _includes(config.library_view, 'start-recording'),

// How many recordings to show
sizes: sizes,
Expand Down Expand Up @@ -1360,7 +1358,8 @@ class AarloGlance extends LitElement {
setConfig(config) {

// save then check new config
this._config = _mergeArrays(config, {})
// this._config = _mergeArrays(config, {})
this._config = config

this.gc = this.getGlobalConfig( config )
this.gs = this.getGlobalState( config )
Expand Down Expand Up @@ -1499,6 +1498,12 @@ class AarloGlance extends LitElement {
} else {
this.toggleSwitch(this.cc.doorBellMuteId)
}
} else if(id.startsWith("camera-light2")) {
if(modified) {
this.moreInfo(this.cc.light2Id)
} else {
this.toggleLight(this.cc.light2Id)
}
} else if(id.startsWith("camera-light")) {
if(modified) {
this.moreInfo(this.cc.lightId)
Expand Down Expand Up @@ -2170,7 +2175,7 @@ class AarloGlance extends LitElement {
async wsStartStream() {
try {
return await this._hass.callWS({
type: this.gc.playDirect ? "aarlo_stream_url" : "camera/stream",
type: this.cc.directPlay ? "aarlo_stream_url" : "camera/stream",
entity_id: this.cc.id,
})
} catch (err) {
Expand Down Expand Up @@ -2228,9 +2233,9 @@ class AarloGlance extends LitElement {
}

getViewType( c ) {
if( c.imageClickSmart ) {
if( c.smartPlayer ) {
return this.gc.isMobile ? "" : "modal"
} else if( c.imageClickModal ) {
} else if( c.modalPlayer ) {
return "modal"
}
return ""
Expand All @@ -2239,8 +2244,8 @@ class AarloGlance extends LitElement {
playStream( ) {
this.cs.autoPlayTimer = null
if ( this.gs.stream === null ) {
if( this.gs.autoPlay ) {
this.cs.autoPlay = this.gs.autoPlay
if( this.cc.autoPlay ) {
this.cs.autoPlay = this.cc.autoPlay
}
this._melement('video-player').muted = this.gs.isMuted
this.wsStartStream()
Expand Down Expand Up @@ -2430,7 +2435,7 @@ class AarloGlance extends LitElement {
}

imageClicked() {
if ( this.cc.imageClickStream ) {
if ( this.cc.playStream ) {
this.playStream()
} else {
this.playLatestRecording()
Expand Down Expand Up @@ -2582,7 +2587,7 @@ class AarloGlance extends LitElement {
}

showDownloadIcon(index) {
if( this.gc.libraryDownload ) {
if( this.lc.download ) {
this._show(`library-a-${index}`)
}
}
Expand Down

0 comments on commit d00b857

Please sign in to comment.