feat: Add 'call' support to improve 2-way audio experience (#2486)
Draws significant inspiration (and direct styling) from https://github.com/dermotduffy/advanced-camera-card/pull/2447 . Thank you @Maudfer ! BREAKING CHANGE: The microphone condition previously bundled two unrelated signals — whether a two-way-audio session was connected and whether the microphone was muted. Connection state is now its own dedicated call condition, and microphone is reserved purely for mute state. Configs are upgraded automatically (the card rewrites affected conditions under overrides, elements, and automations). If you maintain config by hand, convert as follows: If you only used connected: # Before ```yaml condition: microphone connected: true ``` # After ```yaml condition: call call: true ``` If you used both connected and muted — they must be split into two conditions, since they no longer live together: # Before ```yaml condition: microphone connected: true muted: false ``` # After ```yaml condition: and conditions: - condition: call call: true - condition: microphone muted: false ```
This commit is contained in:
committed by
dermotduffy
parent
bb061a1a55
commit
abcba884e5
@@ -3846,5 +3846,210 @@ describe('should handle version specific upgrades', () => {
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
});
|
||||
|
||||
describe('microphone.connected → call condition', () => {
|
||||
it('rewrites connected:true to call:true in an automation', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
automations: [
|
||||
{
|
||||
conditions: [{ condition: 'microphone', connected: true }],
|
||||
actions: [
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'live',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.automations[0].conditions).toEqual([
|
||||
{ condition: 'call', call: true },
|
||||
]);
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('rewrites connected:false to call:false', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
automations: [
|
||||
{
|
||||
conditions: [{ condition: 'microphone', connected: false }],
|
||||
actions: [
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'live',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.automations[0].conditions).toEqual([
|
||||
{ condition: 'call', call: false },
|
||||
]);
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('leaves a microphone.muted only condition untouched', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
automations: [
|
||||
{
|
||||
conditions: [{ condition: 'microphone', muted: true }],
|
||||
actions: [
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'live',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(upgradeConfig(config)).toBeFalsy();
|
||||
expect(config.automations[0].conditions).toEqual([
|
||||
{ condition: 'microphone', muted: true },
|
||||
]);
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('splits a condition with both connected and muted into an AND condition', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
automations: [
|
||||
{
|
||||
conditions: [{ condition: 'microphone', connected: true, muted: false }],
|
||||
actions: [
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'live',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.automations[0].conditions).toEqual([
|
||||
{
|
||||
condition: 'and',
|
||||
conditions: [
|
||||
{ condition: 'call', call: true },
|
||||
{ condition: 'microphone', muted: false },
|
||||
],
|
||||
},
|
||||
]);
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('migrates a microphone.connected nested under or/and/not', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
automations: [
|
||||
{
|
||||
conditions: [
|
||||
{
|
||||
condition: 'or',
|
||||
conditions: [
|
||||
{
|
||||
condition: 'and',
|
||||
conditions: [
|
||||
{
|
||||
condition: 'not',
|
||||
conditions: [{ condition: 'microphone', connected: true }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
actions: [
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'live',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.automations[0].conditions).toEqual([
|
||||
{
|
||||
condition: 'or',
|
||||
conditions: [
|
||||
{
|
||||
condition: 'and',
|
||||
conditions: [
|
||||
{
|
||||
condition: 'not',
|
||||
conditions: [{ condition: 'call', call: true }],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('migrates conditions on elements and overrides', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
elements: [
|
||||
{
|
||||
type: 'custom:advanced-camera-card-conditional',
|
||||
conditions: [{ condition: 'microphone', connected: true }],
|
||||
elements: [{ type: 'icon', icon: 'mdi:phone' }],
|
||||
},
|
||||
],
|
||||
overrides: [
|
||||
{
|
||||
conditions: [{ condition: 'microphone', connected: false }],
|
||||
merge: {},
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
expect(config.elements[0].conditions).toEqual([
|
||||
{ condition: 'call', call: true },
|
||||
]);
|
||||
expect(config.overrides[0].conditions).toEqual([
|
||||
{ condition: 'call', call: false },
|
||||
]);
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
|
||||
it('is idempotent', () => {
|
||||
const config = {
|
||||
type: 'custom:advanced-camera-card',
|
||||
cameras: [{ camera_entity: 'camera.office' }],
|
||||
automations: [
|
||||
{
|
||||
conditions: [{ condition: 'microphone', connected: true }],
|
||||
actions: [
|
||||
{
|
||||
action: 'fire-dom-event',
|
||||
advanced_camera_card_action: 'live',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(upgradeConfig(config)).toBeTruthy();
|
||||
|
||||
// Running upgradeConfig again should not change anything.
|
||||
expect(upgradeConfig(config)).toBeFalsy();
|
||||
expect(config.automations[0].conditions).toEqual([
|
||||
{ condition: 'call', call: true },
|
||||
]);
|
||||
postUpgradeChecks(config);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -17,7 +17,6 @@ it('should contain expected defaults', () => {
|
||||
'menu.buttons.media_player.enabled': false,
|
||||
'menu.buttons.mute.enabled': true,
|
||||
'menu.buttons.play.enabled': true,
|
||||
'menu.style': 'none',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -85,13 +85,18 @@ describe('config defaults', () => {
|
||||
zoomable: true,
|
||||
},
|
||||
live: {
|
||||
auto_mute: ['unselected', 'hidden', 'microphone'],
|
||||
auto_mute: ['unselected', 'hidden', 'microphone', 'call'],
|
||||
auto_pause: [],
|
||||
auto_play: ['selected', 'visible'],
|
||||
auto_unmute: ['microphone'],
|
||||
auto_unmute: ['microphone', 'call'],
|
||||
controls: {
|
||||
builtin: true,
|
||||
call: {
|
||||
button_size: 40,
|
||||
lock: true,
|
||||
},
|
||||
next_previous: {
|
||||
auto_hide: ['call', 'casting'],
|
||||
size: 48,
|
||||
style: 'chevrons',
|
||||
},
|
||||
@@ -133,10 +138,9 @@ describe('config defaults', () => {
|
||||
lazy_unload: [],
|
||||
microphone: {
|
||||
always_connected: false,
|
||||
auto_mute: [],
|
||||
auto_mute: ['call'],
|
||||
auto_unmute: [],
|
||||
disconnect_seconds: 90,
|
||||
lock: true,
|
||||
mute_after_microphone_mute_seconds: 60,
|
||||
},
|
||||
preload: false,
|
||||
@@ -168,6 +172,7 @@ describe('config defaults', () => {
|
||||
controls: {
|
||||
builtin: true,
|
||||
next_previous: {
|
||||
auto_hide: ['casting'],
|
||||
size: 48,
|
||||
style: 'thumbnails',
|
||||
},
|
||||
@@ -212,8 +217,16 @@ describe('config defaults', () => {
|
||||
},
|
||||
menu: {
|
||||
alignment: 'left',
|
||||
auto_hide: ['call', 'casting'],
|
||||
button_size: 40,
|
||||
buttons: {
|
||||
call: {
|
||||
alignment: 'matching',
|
||||
enabled: true,
|
||||
permanent: false,
|
||||
priority: 50,
|
||||
state_color: true,
|
||||
},
|
||||
camera_ui: {
|
||||
alignment: 'matching',
|
||||
enabled: true,
|
||||
@@ -426,6 +439,7 @@ describe('config defaults', () => {
|
||||
},
|
||||
},
|
||||
status_bar: {
|
||||
auto_hide: ['call', 'casting'],
|
||||
height: 40,
|
||||
items: {
|
||||
engine: {
|
||||
@@ -868,6 +882,7 @@ describe('config defaults', () => {
|
||||
it('should include all conditions', () => {
|
||||
const conditions = [
|
||||
{ condition: 'and', conditions: [{ condition: 'initialized' }] },
|
||||
{ condition: 'call', call: true },
|
||||
{ condition: 'camera', cameras: ['camera.office'] },
|
||||
{ condition: 'config', paths: ['menu.style'] },
|
||||
{ condition: 'display_mode', display_mode: 'single' },
|
||||
@@ -885,7 +900,7 @@ describe('config defaults', () => {
|
||||
state: 'down',
|
||||
},
|
||||
{ condition: 'media_loaded', media_loaded: true },
|
||||
{ condition: 'microphone', connected: true, muted: true },
|
||||
{ condition: 'microphone', muted: true },
|
||||
{ condition: 'not', conditions: [{ condition: 'initialized' }] },
|
||||
{
|
||||
condition: 'numeric_state',
|
||||
|
||||
Reference in New Issue
Block a user