-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Digital-Alchemy-TS/registry
- Loading branch information
Showing
23 changed files
with
861 additions
and
103 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"cSpell.words": [ | ||
"zeroconf" | ||
] | ||
} |
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { TServiceParams } from "@digital-alchemy/core"; | ||
|
||
import { TAreaId } from "../dynamic"; | ||
import { AreaCreate, AreaDetails } from "../helpers"; | ||
|
||
export function Area({ hass, context, config, logger }: TServiceParams) { | ||
hass.socket.onConnect(async () => { | ||
if (!config.hass.AUTO_CONNECT_SOCKET || !config.hass.MANAGE_REGISTRY) { | ||
return; | ||
} | ||
hass.area.current = await hass.area.list(); | ||
hass.socket.subscribe({ | ||
context, | ||
event_type: "area_registry_updated", | ||
async exec() { | ||
hass.area.current = await hass.area.list(); | ||
logger.debug(`area registry updated`); | ||
}, | ||
}); | ||
}); | ||
|
||
return { | ||
async create(details: AreaCreate) { | ||
await hass.socket.sendMessage({ | ||
type: "config/area_registry/create", | ||
...details, | ||
}); | ||
}, | ||
current: [] as AreaDetails[], | ||
async delete(area_id: TAreaId) { | ||
await hass.socket.sendMessage({ | ||
area_id, | ||
type: "config/area_registry/delete", | ||
}); | ||
}, | ||
async list() { | ||
return await hass.socket.sendMessage<AreaDetails[]>({ | ||
type: "config/area_registry/list", | ||
}); | ||
}, | ||
async update(details: AreaDetails) { | ||
await hass.socket.sendMessage({ | ||
type: "config/area_registry/update", | ||
...details, | ||
}); | ||
}, | ||
}; | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { TServiceParams } from "@digital-alchemy/core"; | ||
|
||
import { EditAliasOptions, ToggleExpose, UPDATE_REGISTRY } from "../helpers"; | ||
|
||
export function Conversation({ hass, logger }: TServiceParams) { | ||
async function addAlias({ entity, alias }: EditAliasOptions) { | ||
const current = await hass.entity.registry.get(entity); | ||
if (current?.aliases?.includes(alias)) { | ||
logger.debug({ name: entity }, `already has alias {%s}`, alias); | ||
return; | ||
} | ||
await hass.socket.sendMessage({ | ||
entity_id: entity, | ||
type: UPDATE_REGISTRY, | ||
}); | ||
} | ||
|
||
async function removeAlias({ entity, alias }: EditAliasOptions) { | ||
const current = await hass.entity.registry.get(entity); | ||
if (!current?.aliases?.includes(alias)) { | ||
logger.debug({ name: entity }, `does not have alias {%s}`, alias); | ||
return; | ||
} | ||
await hass.socket.sendMessage({ entity_id: entity, type: UPDATE_REGISTRY }); | ||
} | ||
|
||
async function setConversational({ | ||
entity_ids, | ||
assistants, | ||
should_expose, | ||
}: ToggleExpose) { | ||
await hass.socket.sendMessage({ | ||
assistants: [assistants].flat(), | ||
entity_ids: [entity_ids].flat(), | ||
should_expose, | ||
type: UPDATE_REGISTRY, | ||
}); | ||
} | ||
|
||
return { | ||
addAlias, | ||
removeAlias, | ||
setConversational, | ||
}; | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { TServiceParams } from "@digital-alchemy/core"; | ||
|
||
import { DeviceDetails } from "../helpers"; | ||
|
||
export function Device({ hass, config, context, logger }: TServiceParams) { | ||
hass.socket.onConnect(async () => { | ||
if (!config.hass.AUTO_CONNECT_SOCKET || !config.hass.MANAGE_REGISTRY) { | ||
return; | ||
} | ||
hass.device.current = await hass.device.list(); | ||
hass.socket.subscribe({ | ||
context, | ||
event_type: "device_registry_updated", | ||
async exec() { | ||
hass.device.current = await hass.device.list(); | ||
logger.debug(`device registry updated`); | ||
}, | ||
}); | ||
await SubscribeUpdates(); | ||
}); | ||
|
||
async function SubscribeUpdates() { | ||
await hass.socket.sendMessage({ | ||
event_type: "device_registry_updated", | ||
type: "subscribe_events", | ||
}); | ||
} | ||
|
||
async function list() { | ||
return await hass.socket.sendMessage<DeviceDetails[]>({ | ||
type: "config/device_registry/list", | ||
}); | ||
} | ||
|
||
return { | ||
current: [] as DeviceDetails[], | ||
list, | ||
}; | ||
} |
Oops, something went wrong.