Add stream orientation to camera entity registry settings (#13512)

This commit is contained in:
uvjustin 2022-09-28 08:41:32 -07:00 committed by GitHub
parent 182b8f809c
commit 594ee85bbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import { timeCacheEntityPromiseFunc } from "../common/util/time-cache-entity-pro
import { HomeAssistant } from "../types";
import { getSignedPath } from "./auth";
export const CAMERA_ORIENTATIONS = [1, 2, 3, 4, 6, 8];
export const CAMERA_SUPPORT_ON_OFF = 1;
export const CAMERA_SUPPORT_STREAM = 2;
@ -26,6 +27,7 @@ export interface CameraEntity extends HassEntityBase {
export interface CameraPreferences {
preload_stream: boolean;
orientation: number;
}
export interface CameraThumbnail {
@ -109,11 +111,13 @@ export const fetchCameraPrefs = (hass: HomeAssistant, entityId: string) =>
entity_id: entityId,
});
type ValueOf<T extends any[]> = T[number];
export const updateCameraPrefs = (
hass: HomeAssistant,
entityId: string,
prefs: {
preload_stream?: boolean;
orientation?: ValueOf<typeof CAMERA_ORIENTATIONS>;
}
) =>
hass.callWS<CameraPreferences>({

View File

@ -19,7 +19,10 @@ import { computeDomain } from "../../../common/entity/compute_domain";
import { domainIcon } from "../../../common/entity/domain_icon";
import { supportsFeature } from "../../../common/entity/supports-feature";
import { stringCompare } from "../../../common/string/compare";
import { LocalizeFunc } from "../../../common/translations/localize";
import {
LocalizeFunc,
LocalizeKeys,
} from "../../../common/translations/localize";
import "../../../components/ha-alert";
import "../../../components/ha-area-picker";
import "../../../components/ha-expansion-panel";
@ -32,6 +35,7 @@ import type { HaSwitch } from "../../../components/ha-switch";
import "../../../components/ha-textfield";
import {
CameraPreferences,
CAMERA_ORIENTATIONS,
CAMERA_SUPPORT_STREAM,
fetchCameraPrefs,
STREAM_TYPE_HLS,
@ -586,12 +590,12 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
<ha-settings-row>
<span slot="heading"
>${this.hass.localize(
"ui.dialogs.entity_registry.editor.preload_stream"
"ui.dialogs.entity_registry.editor.stream.preload_stream"
)}</span
>
<span slot="description"
>${this.hass.localize(
"ui.dialogs.entity_registry.editor.preload_stream_description"
"ui.dialogs.entity_registry.editor.stream.preload_stream_description"
)}</span
>
<ha-switch
@ -600,6 +604,38 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
>
</ha-switch>
</ha-settings-row>
<ha-settings-row>
<span slot="heading"
>${this.hass.localize(
"ui.dialogs.entity_registry.editor.stream.stream_orientation"
)}</span
>
<span slot="description"
>${this.hass.localize(
"ui.dialogs.entity_registry.editor.stream.stream_orientation_description"
)}</span
>
<ha-select
.label=${this.hass.localize(
"ui.dialogs.entity_registry.editor.stream.stream_orientation"
)}
naturalMenuWidth
fixedMenuPosition
@selected=${this._handleCameraOrientationChanged}
@closed=${stopPropagation}
>
${CAMERA_ORIENTATIONS.map((num) => {
const localizeStr =
"ui.dialogs.entity_registry.editor.stream.stream_orientation_" +
num.toString();
return html`
<mwc-list-item value=${num}>
${this.hass.localize(localizeStr as LocalizeKeys)}
</mwc-list-item>
`;
})}
</ha-select>
</ha-settings-row>
`
: ""}
<ha-expansion-panel
@ -841,6 +877,20 @@ export class EntityRegistrySettings extends SubscribeMixin(LitElement) {
}
}
private async _handleCameraOrientationChanged(ev) {
try {
this._cameraPrefs = await updateCameraPrefs(
this.hass,
this.entry.entity_id,
{
orientation: ev.currentTarget.value,
}
);
} catch (err: any) {
showAlertDialog(this, { text: err.message });
}
}
private _viewStatusChanged(ev: CustomEvent): void {
switch ((ev.target as any).value) {
case "enabled":

View File

@ -898,8 +898,20 @@
"follow_device_area": "Follow device area",
"change_device_area": "Change device area",
"configure_state": "{integration} options",
"preload_stream": "Preload camera stream",
"preload_stream_description": "This keeps the camera stream open in the background so it shows quicker. Warning! This is device intensive."
"stream": {
"preload_stream": "Preload camera stream",
"preload_stream_description": "This keeps the camera stream open in the background so it shows quicker. Warning! This is device intensive.",
"stream_orientation": "Camera stream orientation",
"stream_orientation_description": "The orientation transformation to use for the camera stream.",
"stream_orientation_1": "No orientation transform",
"stream_orientation_2": "Mirror",
"stream_orientation_3": "Rotate 180",
"stream_orientation_4": "Flip",
"stream_orientation_5": "Rotate left and flip",
"stream_orientation_6": "Rotate left",
"stream_orientation_7": "Rotate right and flip",
"stream_orientation_8": "Rotate right"
}
}
},
"helper_settings": {