Add Lock view

Closes #171
This commit is contained in:
DigiLive
2025-04-24 07:26:29 +02:00
parent 5977531bff
commit 0ce7c58642
7 changed files with 89 additions and 6 deletions

View File

@@ -166,6 +166,10 @@ export const ConfigurationDefaults: StrategyDefaults = {
order: 2,
hidden: false,
},
lock: {
order: 10,
hidden: false,
},
scene: {
order: 9,
hidden: false,

View File

@@ -40,7 +40,10 @@
"lights": "Leuchten"
},
"lock": {
"locks": "Schlösser"
"locked": "Gesperrt",
"all_locks": "Alle Schlösser",
"locks": "Schlösser",
"unlocked": "Entsperrt"
},
"media_player": {
"media_players": "Wiedergabegeräte"

View File

@@ -40,7 +40,10 @@
"lights": "Lights"
},
"lock": {
"locks": "Locks"
"all_locks": "All Locks",
"locked": "Locked",
"locks": "Locks",
"unlocked": "Unlocked"
},
"media_player": {
"media_players": "Media Players"

View File

@@ -40,7 +40,10 @@
"lights": "Luces"
},
"lock": {
"locks": "Candados"
"all_locks": "Todas las Candados",
"locked": "Locked",
"locks": "Candados",
"unlocked": "Desbloqueado"
},
"media_player": {
"media_players": "Reproductores Multimedia"

View File

@@ -40,7 +40,10 @@
"lights": "Lampen"
},
"lock": {
"locks": "Sloten"
"all_locks": "Alle Sloten",
"locked": "Vergrendeld",
"locks": "Sloten",
"unlocked": "Ontgrendeld"
},
"media_player": {
"media_players": "Mediaspelers"

View File

@@ -45,7 +45,18 @@ const SUPPORTED_DOMAINS = [
*
* This constant array defines the views that are supported by the strategy.
*/
const SUPPORTED_VIEWS = ['camera', 'climate', 'cover', 'fan', 'home', 'light', 'scene', 'switch', 'vacuum'] as const;
const SUPPORTED_VIEWS = [
'camera',
'climate',
'cover',
'fan',
'home',
'light',
'lock',
'scene',
'switch',
'vacuum',
] as const;
/**
* List of supported chips.
@@ -245,7 +256,7 @@ export interface StrategyArea extends AreaRegistryEntry {
* @property {boolean} fan_count - Chip to display the number of fans on.
* @property {boolean} light_count - Chip to display the number of lights on.
* @property {boolean} switch_count - Chip to display the number of switches on.
* @property {"auto" | `weather.${string}`} weather_entity - Entity id for the weather chip to use.
* @property {'auto' | `weather.${string}`} weather_entity - Entity id for the weather chip to use.
* Accepts `weather.` ids or `auto` only.
*/
export interface ChipConfiguration {

56
src/views/LockView.ts Normal file
View File

@@ -0,0 +1,56 @@
// noinspection JSUnusedGlobalSymbols Class is dynamically imported.
import { Registry } from '../Registry';
import { CustomHeaderCardConfig } from '../types/strategy/strategy-cards';
import { ViewConfig } from '../types/strategy/strategy-views';
import { localize } from '../utilities/localize';
import AbstractView from './AbstractView';
/**
* Vacuum View Class.
*
* Used to create a view configuration for entities of the lock domain.
*/
class LockView extends AbstractView {
/** The domain of the entities that the view is representing. */
static readonly domain = 'vacuum' as const;
/** Returns the default configuration object for the view. */
static getDefaultConfig(): ViewConfig {
return {
title: localize('locks.locks'),
path: 'locks',
icon: 'mdi:lock-open',
subview: false,
headerCardConfiguration: {
iconOn: 'mdi:lock-open',
iconOff: 'mdi:lock',
onService: 'lock.lock',
offService: 'lock.unlock',
},
};
}
/** Returns the default configuration of the view's Header card. */
static getViewHeaderCardConfig(): CustomHeaderCardConfig {
return {
title: localize('lock.all_locks'),
subtitle:
`${Registry.getCountTemplate(LockView.domain, 'ne', 'locked')} ${localize('lock.locks')} ` +
localize('lock.unlocked'),
};
}
/**
* Class constructor.
*
* @param {ViewConfig} [customConfiguration] Custom view configuration.
*/
constructor(customConfiguration?: ViewConfig) {
super();
this.initializeViewConfig(LockView.getDefaultConfig(), customConfiguration, LockView.getViewHeaderCardConfig());
}
}
export default LockView;