feat: Add out of the box support for Reolink PTZ (#1982)

- Closes: #1964
This commit is contained in:
Dermot Duffy
2025-03-26 21:26:02 -07:00
committed by GitHub
parent f6bb8001e3
commit b5eee5878a
50 changed files with 953 additions and 679 deletions
+8 -8
View File
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, it, vi } from 'vitest';
import {
createEntityRegistryCache,
EntityRegistryManager,
EntityRegistryManagerLive,
} from '../../../../../src/utils/ha/registry/entity';
import { homeAssistantWSRequest } from '../../../../../src/utils/ha/ws-request';
import { createHASS, createRegistryEntity } from '../../../../test-utils.js';
@@ -21,7 +21,7 @@ describe('EntityRegistryManager', () => {
cache.add(testEntity);
const manager = new EntityRegistryManager(cache);
const manager = new EntityRegistryManagerLive(cache);
expect(await manager.getEntity(createHASS(), 'test')).toEqual(testEntity);
expect(homeAssistantWSRequest).not.toHaveBeenCalled();
@@ -30,7 +30,7 @@ describe('EntityRegistryManager', () => {
it('should fetch and cache when not cached', async () => {
const testEntity = createRegistryEntity({ entity_id: 'test' });
const manager = new EntityRegistryManager(createEntityRegistryCache());
const manager = new EntityRegistryManagerLive(createEntityRegistryCache());
vi.mocked(homeAssistantWSRequest).mockResolvedValueOnce(testEntity);
expect(await manager.getEntity(createHASS(), 'test')).toEqual(testEntity);
@@ -43,7 +43,7 @@ describe('EntityRegistryManager', () => {
it('should return null when entity does not exist', async () => {
vi.mocked(homeAssistantWSRequest).mockRejectedValueOnce(new Error('Not found'));
const manager = new EntityRegistryManager(createEntityRegistryCache());
const manager = new EntityRegistryManagerLive(createEntityRegistryCache());
expect(await manager.getEntity(createHASS(), 'missing')).toBeNull();
vi.mocked(expect(console.warn)).toBeCalledWith('Not found');
@@ -57,7 +57,7 @@ describe('EntityRegistryManager', () => {
const cache = createEntityRegistryCache();
cache.add(cachedEntity);
const manager = new EntityRegistryManager(cache);
const manager = new EntityRegistryManagerLive(cache);
vi.mocked(homeAssistantWSRequest).mockResolvedValueOnce(notCachedEntity);
vi.mocked(homeAssistantWSRequest).mockRejectedValueOnce(new Error('Not found'));
@@ -79,7 +79,7 @@ describe('EntityRegistryManager', () => {
const entity = createRegistryEntity({ entity_id: 'cached' });
vi.mocked(homeAssistantWSRequest).mockResolvedValueOnce([entity]);
const manager = new EntityRegistryManager(createEntityRegistryCache());
const manager = new EntityRegistryManagerLive(createEntityRegistryCache());
await manager.fetchEntityList(hass);
@@ -103,7 +103,7 @@ describe('EntityRegistryManager', () => {
const hass = createHASS();
vi.mocked(homeAssistantWSRequest).mockRejectedValueOnce(new Error('Fetch error'));
const manager = new EntityRegistryManager(createEntityRegistryCache());
const manager = new EntityRegistryManagerLive(createEntityRegistryCache());
await manager.fetchEntityList(hass);
@@ -121,7 +121,7 @@ describe('EntityRegistryManager', () => {
notMatchingEntity,
]);
const manager = new EntityRegistryManager(createEntityRegistryCache());
const manager = new EntityRegistryManagerLive(createEntityRegistryCache());
expect(
await manager.getMatchingEntities(
hass,
+47
View File
@@ -0,0 +1,47 @@
import { HomeAssistant } from '../../../../../src/ha/types';
import { RegistryCache } from '../../../../../src/utils/ha/registry/cache';
import {
Entity,
EntityRegistryManager,
} from '../../../../../src/utils/ha/registry/entity/types';
export class EntityRegistryManagerMock implements EntityRegistryManager {
protected _cache: RegistryCache<Entity>;
protected _fetchedEntityList = false;
constructor(data?: Entity[]) {
this._cache = new RegistryCache<Entity>((ent) => ent.entity_id);
this._cache.add(data ?? []);
}
public async getEntity(
_hass: HomeAssistant,
entityID: string,
): Promise<Entity | null> {
return this._cache.get(entityID);
}
public async getMatchingEntities(
_hass: HomeAssistant,
func: (arg: Entity) => boolean,
): Promise<Entity[]> {
return this._cache.getMatches(func);
}
public async getEntities(
hass: HomeAssistant,
entityIDs: string[],
): Promise<Map<string, Entity>> {
const output: Map<string, Entity> = new Map();
for (const entityID of entityIDs) {
const entityData = await this.getEntity(hass, entityID);
if (entityData) {
output.set(entityID, entityData);
}
}
return output;
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public async fetchEntityList(_hass: HomeAssistant): Promise<void> {}
}