Skip to content

Commit

Permalink
1.10.0
Browse files Browse the repository at this point in the history
Added dynamic mode lists for media device (source/sound mode)
  • Loading branch information
RonnyWinkler committed Jan 13, 2025
1 parent fb7ce66 commit 08542c0
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .homeychangelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,10 @@
"1.9.0": {
"en": "Added widget for alarm control panel.",
"de": "Widget für Alarmzentrale hinzugefügt."
},
"1.10.0": {
"en": "Added dynamic mode lists for media device (source/sound mode)",
"de": "Dynamische Modi für Medien-Geräte (Quell/Sound-Modus) hinzugefügt."
}

}
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "io.home-assistant.community",
"version": "1.9.0",
"version": "1.10.0",
"compatibility": ">=12.2.0",
"sdk": 3,
"brandColor": "#0DA6EA",
Expand Down
20 changes: 20 additions & 0 deletions .homeycompose/capabilities/media_sound_mode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"type": "enum",
"title": {
"en": "Sound mode",
"de": "Klangmodus",
"nl": "Geluidsmodus"
},
"desc": {
"en": "Sound mode",
"de": "Klangmodus",
"nl": "Geluidsmodus"
},
"getable": true,
"setable": true,
"insights": true,
"icon": "/assets/capability_icons/media_sound_mode.svg",
"uiComponent": "picker",
"values": [
]
}
21 changes: 21 additions & 0 deletions .homeycompose/capabilities/media_source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"highlight": true,
"type": "enum",
"title": {
"en": "Source",
"de": "Quelle",
"nl": "Bron"
},
"desc": {
"en": "Source (input)",
"de": "Quelle (Eingang)",
"nl": "Bron (invoer)"
},
"getable": true,
"setable": true,
"insights": true,
"icon": "/assets/capability_icons/media_source.svg",
"uiComponent": "picker",
"values": [
]
}
23 changes: 23 additions & 0 deletions .homeycompose/flow/triggers/media_sound_mode_changed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"title": {
"en": "Media sound mode changed",
"de": "Medien-Klangmodus hat sich geændert",
"nl": "Geluidsmodus gewijzigd"
},
"tokens": [{
"name": "media_sound_mode",
"type": "string",
"title": {
"en": "Sound mode",
"de": "Klangmodus",
"nl": "Geluidsmodus"
},
"example": "5ch Stereo"
}
],
"args": [{
"name": "device",
"type": "device",
"filter": "driver_id=media"
}]
}
23 changes: 23 additions & 0 deletions .homeycompose/flow/triggers/media_source_changed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"title": {
"en": "Media source changed",
"de": "Medien-Quelle hat sich geändert",
"nl": "Mediabron gewijzigd"
},
"tokens": [{
"name": "media_source",
"type": "string",
"title": {
"en": "Source",
"de": "Quelle",
"nl": "Bron"
},
"example": "HDMI 1"
}
],
"args": [{
"name": "device",
"type": "device",
"filter": "driver_id=media"
}]
}
6 changes: 3 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"type": "node",
"request": "attach",
"restart": true,
"name": "Attach HA to Homey 23 DEV Docker",
"name": "Attach HA to Homey Pro 23 DEV Docker",
"address": "192.168.1.42",
"port": 9229,
"localRoot": "${workspaceFolder}",
Expand All @@ -51,7 +51,7 @@
"type": "node",
"request": "attach",
"restart": true,
"name": "Attach HA to Homey23 Docker",
"name": "Attach HA to Homey Pro 23 Docker",
"address": "192.168.1.15",
"port": 9229,
"localRoot": "${workspaceFolder}",
Expand All @@ -62,7 +62,7 @@
"type": "node",
"request": "attach",
"restart": true,
"name": "Attach HA to Homey 19 Dev",
"name": "Attach HA to Homey Pro 19 DEV",
"address": "192.168.1.13",
"port": 9225,
"localRoot": "${workspaceFolder}",
Expand Down
95 changes: 94 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_comment": "This file is generated. Please edit .homeycompose/app.json instead.",
"id": "io.home-assistant.community",
"version": "1.9.0",
"version": "1.10.0",
"compatibility": ">=12.2.0",
"sdk": 3,
"brandColor": "#0DA6EA",
Expand Down Expand Up @@ -994,6 +994,60 @@
],
"id": "measure_numeric_changed"
},
{
"title": {
"en": "Media sound mode changed",
"de": "Medien-Klangmodus hat sich geændert",
"nl": "Geluidsmodus gewijzigd"
},
"tokens": [
{
"name": "media_sound_mode",
"type": "string",
"title": {
"en": "Sound mode",
"de": "Klangmodus",
"nl": "Geluidsmodus"
},
"example": "5ch Stereo"
}
],
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=media"
}
],
"id": "media_sound_mode_changed"
},
{
"title": {
"en": "Media source changed",
"de": "Medien-Quelle hat sich geändert",
"nl": "Mediabron gewijzigd"
},
"tokens": [
{
"name": "media_source",
"type": "string",
"title": {
"en": "Source",
"de": "Quelle",
"nl": "Bron"
},
"example": "HDMI 1"
}
],
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=media"
}
],
"id": "media_source_changed"
},
{
"title": {
"en": "Presence state changed",
Expand Down Expand Up @@ -10699,6 +10753,45 @@
"insights": true,
"icon": "/assets/capability_icons/measure_numeric.svg"
},
"media_sound_mode": {
"type": "enum",
"title": {
"en": "Sound mode",
"de": "Klangmodus",
"nl": "Geluidsmodus"
},
"desc": {
"en": "Sound mode",
"de": "Klangmodus",
"nl": "Geluidsmodus"
},
"getable": true,
"setable": true,
"insights": true,
"icon": "/assets/capability_icons/media_sound_mode.svg",
"uiComponent": "picker",
"values": []
},
"media_source": {
"highlight": true,
"type": "enum",
"title": {
"en": "Source",
"de": "Quelle",
"nl": "Bron"
},
"desc": {
"en": "Source (input)",
"de": "Quelle (Eingang)",
"nl": "Bron (invoer)"
},
"getable": true,
"setable": true,
"insights": true,
"icon": "/assets/capability_icons/media_source.svg",
"uiComponent": "picker",
"values": []
},
"media_unjoin": {
"type": "boolean",
"title": {
Expand Down
1 change: 1 addition & 0 deletions assets/capability_icons/media_sound_mode.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/capability_icons/media_source.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 83 additions & 9 deletions drivers/media/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ class MediaDevice extends BaseDevice {
await this._onCapabilityMediaUnjoin(value, opts)
});
}
if(this.hasCapability("media_source")) {
this.registerCapabilityListener('media_source', async (value, opts) => {
await this._onCapabilityMediaSource(value, opts)
});
}
if(this.hasCapability("media_sound_mode")) {
this.registerCapabilityListener('media_sound_mode', async (value, opts) => {
await this._onCapabilityMediaSoundMode(value, opts)
});
}

// maintenance actions
this.registerCapabilityListener('button.reconnect', async () => {
Expand All @@ -78,6 +88,17 @@ class MediaDevice extends BaseDevice {
async updateCapabilities(){
// Add new capabilities (if not already added)
try{

if (this.hasCapability('media_source'))
{
await this.removeCapability('media_source');
}
if (this.hasCapability('media_sound_mode'))
{
await this.removeCapability('media_sound_mode');
}


if (!this.hasCapability('button.reconnect'))
{
await this.addCapability('button.reconnect');
Expand All @@ -86,6 +107,16 @@ class MediaDevice extends BaseDevice {
{
await this.addCapability('media_unjoin');
}
if (!this.hasCapability('media_source'))
{
await this.addCapability('media_source');
await this.setStoreValue("sourceList", '');
}
if (!this.hasCapability('media_sound_mode'))
{
await this.addCapability('media_sound_mode');
await this.setStoreValue("soundModeList", '');
}
}
catch(error){
this.error("Error adding capability: "+error.message);
Expand Down Expand Up @@ -237,20 +268,55 @@ class MediaDevice extends BaseDevice {
}
}
if (data.attributes.source_list == null || data.attributes.source_list == undefined){
await this.setStoreValue("sourceList", '');
await this.setStoreValue("canSelectSource", false);
if (this.getStoreValue("sourceList") != ''){
await this.setStoreValue("sourceList", '');
await this.setStoreValue("canSelectSource", false);
await this.setCapabilityEnumList('media_source', []);
await this.setCapabilityValue('media_source', null);
}
}
else{
await this.setStoreValue("sourceList", JSON.stringify(data.attributes.source_list));
await this.setStoreValue("canSelectSource", true);
if (this.getStoreValue("sourceList") != JSON.stringify(data.attributes.source_list)){
await this.setStoreValue("sourceList", JSON.stringify(data.attributes.source_list));
await this.setStoreValue("canSelectSource", true);
await this.setCapabilityEnumList('media_source', data.attributes.source_list);
}
if (this.hasCapability('media_source') && data.attributes.source){
try{
await this.setCapabilityValue('media_source', data.attributes.source);
}
catch(error){
this.log("Error changing capability 'media_source' to: "+data.attributes.source);
}
}
else{
await this.setCapabilityValue('media_source', null);
}
}
if (data.attributes.sound_mode_list == null || data.attributes.sound_mode_list == undefined){
await this.setStoreValue("soundModeList", '');
await this.setStoreValue("canSelectSoundMode", false);
if (this.getStoreValue("soundModeList") != ''){
await this.setStoreValue("soundModeList", '');
await this.setStoreValue("canSelectSoundMode", false);
await this.setCapabilityEnumList('soundModeList', []);
}
}
else{
await this.setStoreValue("soundModeList", JSON.stringify(data.attributes.sound_mode_list));
await this.setStoreValue("canSelectSoundMode", true);
if (this.getStoreValue("soundModeList") != JSON.stringify(data.attributes.sound_mode_list)){
await this.setStoreValue("soundModeList", JSON.stringify(data.attributes.sound_mode_list));
await this.setStoreValue("canSelectSoundMode", true);
await this.setCapabilityEnumList('media_sound_mode', data.attributes.sound_mode_list);
}
if (this.hasCapability('media_sound_mode') && data.attributes.sound_mode){
try{
await this.setCapabilityValue('media_sound_mode', data.attributes.sound_mode);
}
catch(error){
this.log("Error changing capability 'media_sound_mode' to: "+data.attributes.sound_mode);
}
}
else{
await this.setCapabilityValue('media_sound_mode', null);
}
}

let entityPicture = null;
Expand Down Expand Up @@ -413,7 +479,15 @@ class MediaDevice extends BaseDevice {
});

}


async _onCapabilityMediaSource( value, opts ){
await this.setSource(value);
}

async _onCapabilityMediaSoundMode( value, opts ){
await this.setSoundMode(value);
}

// Autocompletion lists & Flow actions ===========================================================================================
getSourceList(){
if (this.getStoreValue("canSelectSource") == true){
Expand Down

0 comments on commit 08542c0

Please sign in to comment.