Skip to content

Commit

Permalink
fix: Do not show the cameras menu with <= 1 camera (#1616)
Browse files Browse the repository at this point in the history
  • Loading branch information
dermotduffy authored Oct 5, 2024
1 parent e75afbc commit b5c2f00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/components-lib/menu-button-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class MenuButtonController {
// Show all cameras in the menu rather than just cameras that support the
// current view for a less surprising UX.
const menuCameraIDs = cameraManager.getStore().getCameraIDsWithCapability('menu');
if (menuCameraIDs.size) {
if (menuCameraIDs.size > 1) {
const menuItems = Array.from(
cameraManager.getStore().getCameraConfigEntries(menuCameraIDs),
([cameraID, config]) => {
Expand Down
12 changes: 8 additions & 4 deletions tests/components-lib/menu-button-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
createCameraConfig,
createCameraManager,
createCapabilities,
createCardAPI,
createConfig,
createHASS,
createMediaCapabilities,
Expand Down Expand Up @@ -115,7 +114,7 @@ describe('MenuButtonController', () => {
});

describe('should have cameras menu', () => {
it('with multiple cameras', () => {
it('should have cameras menu with multiple cameras', () => {
const cameraManager = createCameraManager();
vi.mocked(cameraManager.getStore).mockReturnValue(
createStore([
Expand Down Expand Up @@ -167,13 +166,18 @@ describe('MenuButtonController', () => {
});
});

it('without a visible camera', () => {
it('should not have cameras menu with <= 1 camera', () => {
const cameraManager = createCameraManager();
vi.mocked(cameraManager.getStore).mockReturnValue(
createStore([
{ cameraID: 'camera-1', config: createCameraConfig({ hide: true }) },
{ cameraID: 'camera-1', capabilities: createCapabilities({ menu: true }) },
{ cameraID: 'camera-3', capabilities: createCapabilities({ menu: false }) },
]),
);
vi.mocked(cameraManager).getCameraMetadata.mockReturnValue({
title: 'title',
icon: 'icon',
});
const buttons = calculateButtons(controller, { cameraManager: cameraManager });

expect(buttons).not.toEqual(
Expand Down

0 comments on commit b5c2f00

Please sign in to comment.