Skip to content

Commit

Permalink
feat: Add new casting profile
Browse files Browse the repository at this point in the history
  • Loading branch information
dermotduffy committed Sep 23, 2024
1 parent 9c68b30 commit b6e6b04
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 6 deletions.
20 changes: 16 additions & 4 deletions docs/configuration/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@ the user.
?> Profiles are applied top to bottom. If multiple profiles change a configuration default, then the last one "wins"
| Profile name | Purpose |
| ----------------- | -------------------------- |
| `low-performance` | Increase card performance. |
| `scrubbing` | Allow media "scrubbing". |
| Profile name | Purpose |
| ----------------- | ---------------------------------------------- |
| `casting` | Configure the card to be casted. |
| `low-performance` | Configure the card for lower end devices. |
| `scrubbing` | Configure the card to allow "video scrubbing". |

## `casting`

To aid casting the card to Chromecast devices, the `casting` profile will adjust card defaults to better suit casting. You may wish to combine this the `low-performance` profile below, since Chromecast devices tend to lower performance. To combine, list `low-performance` first, to allow `casting` to take precedence:

```yaml
profiles:
- low-performance
- casting
```

## `low-performance`

Expand All @@ -42,6 +53,7 @@ See the [source code](https://github.com/dermotduffy/frigate-hass-card/blob/dev/

```yaml
profiles:
- casting
- low-performance
- scrubbing
```
11 changes: 11 additions & 0 deletions src/config/profiles/casting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
CONF_DIMENSIONS_ASPECT_RATIO,
CONF_LIVE_AUTO_UNMUTE,
CONF_MENU_STYLE,
} from '../../const.js';

export const CASTING_PROFILE = {
[CONF_MENU_STYLE]: 'none' as const,
[CONF_LIVE_AUTO_UNMUTE]: ['selected', 'visible'],
[CONF_DIMENSIONS_ASPECT_RATIO]: '16:9',
};
4 changes: 3 additions & 1 deletion src/config/profiles/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { deepRemoveDefaults } from '../../utils/zod.js';
import { getConfigValue, setConfigValue } from '../management.js';
import { ProfileType, RawFrigateCardConfig, frigateCardConfigSchema } from '../types.js';
import { deepRemoveDefaults } from '../../utils/zod.js';
import { CASTING_PROFILE } from './casting.js';
import { LOW_PERFORMANCE_PROFILE } from './low-performance.js';
import { SCRUBBING_PROFILE } from './scrubbing.js';

const PROFILES = {
casting: CASTING_PROFILE,
'low-performance': LOW_PERFORMANCE_PROFILE,
scrubbing: SCRUBBING_PROFILE,
};
Expand Down
2 changes: 1 addition & 1 deletion src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ export interface CardWideConfig {
// *************************************************************************
// *** Profile Configuration ***
// *************************************************************************
const PROFILES = ['low-performance', 'scrubbing'] as const;
const PROFILES = ['casting', 'low-performance', 'scrubbing'] as const;
export type ProfileType = (typeof PROFILES)[number];
export const profilesSchema = z.enum(PROFILES).array().optional();

Expand Down
1 change: 1 addition & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ export class FrigateCardEditor extends LitElement implements LovelaceCardEditor

protected _profiles: EditorSelectOption[] = [
{ value: '', label: '' },
{ value: 'casting', label: localize('config.profiles.casting') },
{ value: 'low-performance', label: localize('config.profiles.low-performance') },
{ value: 'scrubbing', label: localize('config.profiles.scrubbing') },
];
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
"warning": "Aquesta targeta està en mode de perfil baix, de manera que els valors predeterminats han canviat per optimitzar el rendiment"
},
"profiles": {
"casting": "",
"editor_label": "",
"low-performance": "",
"scrubbing": ""
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
"warning": "This card is in low profile mode so defaults have changed to optimize performance"
},
"profiles": {
"casting": "Casting",
"editor_label": "Configuration profiles",
"low-performance": "Low performance",
"scrubbing": "Video scrubbing"
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
"warning": "Cette carte est en mode profil bas, les paramètres par défaut ont donc été modifiés pour optimiser les performances."
},
"profiles": {
"casting": "",
"editor_label": "Configuration des profils",
"low-performance": "Basse performance",
"scrubbing": "Balayage vidéo"
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
"warning": "Questa scheda è in modalità basso profilo, quindi le impostazioni predefinite sono state modificate per ottimizzare le prestazioni"
},
"profiles": {
"casting": "",
"editor_label": "",
"low-performance": "",
"scrubbing": ""
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
"warning": "Este cartão está no modo de baixo desempenho, então os padrões foram alterados para otimizar o desempenho"
},
"profiles": {
"casting": "",
"editor_label": "",
"low-performance": "",
"scrubbing": ""
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@
"warning": "Avisos"
},
"profiles": {
"casting": "",
"editor_label": "",
"low-performance": "",
"scrubbing": ""
Expand Down
24 changes: 24 additions & 0 deletions tests/config/profiles/casting.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect, it } from 'vitest';
import { setProfiles } from '../../../src/config/profiles';
import { frigateCardConfigSchema } from '../../../src/config/types';
import { createRawConfig } from '../../test-utils';
import { CASTING_PROFILE } from '../../../src/config/profiles/casting';

it('should contain expected defaults', () => {
expect(CASTING_PROFILE).toEqual({
'dimensions.aspect_ratio': '16:9',
'live.auto_unmute': ['selected', 'visible'],
'menu.style': 'none',
});
});

it('should be parseable after application', () => {
const rawInputConfig = createRawConfig();
const parsedConfig = frigateCardConfigSchema.parse(rawInputConfig);

setProfiles(rawInputConfig, parsedConfig, ['casting']);

// Reparse the config to ensure the profile did not introduce errors.
const parseResult = frigateCardConfigSchema.safeParse(parsedConfig);
expect(parseResult.success, parseResult.error?.toString()).toBeTruthy();
});

0 comments on commit b6e6b04

Please sign in to comment.