-
Notifications
You must be signed in to change notification settings - Fork 3.4k
possibility to choose the camera in case of multiple entities #26892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Edsol
wants to merge
7
commits into
home-assistant:dev
Choose a base branch
from
Edsol:area_card_camera_entities
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
16c344b
possibility to choose the camera in case of multiple entities
Edsol f2cef02
Merge branch 'dev' into area_card_camera_entities
Edsol 9ba13f3
Merge branch 'dev' into area_card_camera_entities
Edsol 6b07c76
resolved the types and TypeScript errors
Edsol 33dcba5
avoid breaking change with default camera, fix friendly camera names
Edsol bf0a34b
Merge branch 'home-assistant:dev' into area_card_camera_entities
Edsol 64ccb8b
use camera selector instead select selector
Edsol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,7 @@ const cardConfigStruct = assign( | |
| display_type: optional(enums(["compact", "icon", "picture", "camera"])), | ||
| vertical: optional(boolean()), | ||
| camera_view: optional(string()), | ||
| camera_entity: optional(string()), | ||
| alert_classes: optional(array(string())), | ||
| sensor_classes: optional(array(string())), | ||
| features: optional(array(any())), | ||
|
|
@@ -64,6 +65,24 @@ const cardConfigStruct = assign( | |
| }) | ||
| ); | ||
|
|
||
| let availableCameraEntities; | ||
|
|
||
| export const getCameraEntities = memoizeOne( | ||
| ( | ||
| // entities: HomeAssistant["entities"], | ||
| hass: any, | ||
| areaId: string | ||
| ): string[] | undefined => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't really return undefined does it? |
||
| const cameraFilter = generateEntityFilter(hass!, { | ||
| area: areaId, | ||
| entity_category: "none", | ||
| domain: "camera", | ||
| }); | ||
|
|
||
| return Object.keys(hass.entities).filter(cameraFilter); | ||
| } | ||
| ); | ||
|
|
||
| @customElement("hui-area-card-editor") | ||
| export class HuiAreaCardEditor | ||
| extends LitElement | ||
|
|
@@ -82,7 +101,8 @@ export class HuiAreaCardEditor | |
| localize: LocalizeFunc, | ||
| displayType: AreaCardDisplayType, | ||
| binaryClasses: SelectOption[], | ||
| sensorClasses: SelectOption[] | ||
| sensorClasses: SelectOption[], | ||
| cameraEntities: string[] | undefined | ||
| ) => | ||
| [ | ||
| { name: "area", selector: { area: {} } }, | ||
|
|
@@ -154,6 +174,29 @@ export class HuiAreaCardEditor | |
| }, | ||
| ] as const satisfies readonly HaFormSchema[]) | ||
| : []), | ||
| ...(displayType === "camera" | ||
| ? ([ | ||
| { | ||
| name: "camera_entity", | ||
| required: true, | ||
| default: cameraEntities?.[0], | ||
| selector: { | ||
| select: { | ||
Edsol marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| options: | ||
| cameraEntities === undefined | ||
| ? [] | ||
| : cameraEntities.map((entityId) => ({ | ||
| label: | ||
| this.hass!.states[entityId]?.attributes | ||
| ?.friendly_name || entityId, | ||
| value: entityId, | ||
| })), | ||
| mode: "dropdown", | ||
| }, | ||
| }, | ||
| }, | ||
| ] as const satisfies readonly HaFormSchema[]) | ||
| : []), | ||
| ], | ||
| }, | ||
| { | ||
|
|
@@ -299,6 +342,11 @@ export class HuiAreaCardEditor | |
|
|
||
| const displayType = | ||
| config.display_type || (config.show_camera ? "camera" : "picture"); | ||
|
|
||
| availableCameraEntities = config.area | ||
| ? getCameraEntities(this.hass, config.area) | ||
| : []; | ||
|
|
||
| this._config = { | ||
| ...config, | ||
| display_type: displayType, | ||
|
|
@@ -385,7 +433,8 @@ export class HuiAreaCardEditor | |
| this.hass.localize, | ||
| displayType, | ||
| binarySelectOptions, | ||
| sensorSelectOptions | ||
| sensorSelectOptions, | ||
| availableCameraEntities | ||
| ); | ||
|
|
||
| const vertical = this._config.vertical && displayType === "compact"; | ||
|
|
@@ -454,11 +503,23 @@ export class HuiAreaCardEditor | |
| private _valueChanged(ev: CustomEvent): void { | ||
| const newConfig = ev.detail.value as AreaCardConfig; | ||
|
|
||
| availableCameraEntities = newConfig.area | ||
| ? getCameraEntities(this.hass, newConfig.area) | ||
| : []; | ||
|
|
||
| if (this._config!.area !== newConfig.area) { | ||
| delete newConfig.camera_entity; | ||
| } | ||
|
|
||
| const config: AreaCardConfig = { | ||
| features: this._config!.features, | ||
| ...newConfig, | ||
| }; | ||
|
|
||
| if (this._config!.area !== newConfig.area) { | ||
| delete newConfig.camera_entity; | ||
| } | ||
|
|
||
| if (config.display_type !== "camera") { | ||
| delete config.camera_view; | ||
| } | ||
|
|
@@ -543,6 +604,7 @@ export class HuiAreaCardEditor | |
| return this.hass!.localize("ui.panel.lovelace.editor.card.area.name"); | ||
| case "name": | ||
| case "camera_view": | ||
| case "camera_entity": | ||
| case "content": | ||
| case "interactions": | ||
| return this.hass!.localize( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.