Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 44 additions & 17 deletions src/services/HomeassistantService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,19 @@ export default class HomeassistantService {
* @param update_percentage
* @param in_progress
*/
public static async publishUpdateProgressMessage(container: any, client: any, update_percentage: number | null = null, in_progress: boolean = false) {
if (typeof container == "string") {
container = DockerService.docker.getContainer(container).inspect();
}
public static async publishUpdateProgressMessage(container: any, client: any, update_percentage: number | null = null, in_progress: boolean = false) {
if (typeof container === "string") {
try {
container = await DockerService.docker
.getContainer(container)
.inspect();
} catch (error: any) {
logger.warn(
`Could not inspect container ${container}: ${error.message || error}`
);
return;
}
}

const image = container.Config.Image.split(":")[0];
const formatedImage = image.replace(/[\/.:;,+*?@^$%#!&"'`|<>{}\[\]()-\s\u0000-\u001F\u007F]/g, "_");
Expand All @@ -461,15 +470,24 @@ export default class HomeassistantService {
this.publishMessage(client, updateTopic, updatePayload, {retain: false});
}

public static async publishAbortUpdateMessage(container: any, client: any) {
if (typeof container == "string") {
container = DockerService.docker.getContainer(container).inspect();
}

if (!container) {
logger.error(`ABORT: Failed to find container ${container}`);
return;
}
public static async publishAbortUpdateMessage(container: any, client: any) {
try {
if (typeof container === "string") {
container = await DockerService.docker
.getContainer(container)
.inspect();
}
} catch (error: any) {
logger.warn(
`Could not inspect container ${container}: ${error.message || error}`
);
return;
}

if (!container) {
logger.error(`ABORT: Failed to find container ${container}`);
return;
}

const image = container?.Config?.Image?.split(":")[0];
const formatedImage = image?.replace(/[\/.:;,+*?@^$%#!&"'`|<>{}\[\]()-\s\u0000-\u001F\u007F]/g, "_");
Expand All @@ -491,10 +509,19 @@ export default class HomeassistantService {
* @param container
* @param client
*/
public static async publishImageUpdateMessage(container: any, client: any, update_percentage: number | null = null, remaining: number | null = null, state: string | null = null, log: boolean = true) {
if (typeof container == "string") {
container = DockerService.docker.getContainer(container).inspect();
}
public static async publishImageUpdateMessage(container: any, client: any, update_percentage: number | null = null, remaining: number | null = null, state: string | null = null, log: boolean = true) {
if (typeof container === "string") {
try {
container = await DockerService.docker
.getContainer(container)
.inspect();
} catch (error: any) {
logger.warn(
`Could not inspect container ${container}: ${error.message || error}`
);
return;
}
}

const image = container.Config.Image.split(":")[0];
const formatedImage = image.replace(/[\/.:;,+*?@^$%#!&"'`|<>{}\[\]()-\s\u0000-\u001F\u007F]/g, "_");
Expand Down