Skip to content

Commit

Permalink
Add filter for clear_new
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed Jun 6, 2020
1 parent 36de035 commit 0095cff
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 70 deletions.
35 changes: 9 additions & 26 deletions src/components/hacs-tabbed-menu.ts
@@ -1,22 +1,11 @@
import {
LitElement,
customElement,
property,
html,
css,
TemplateResult,
} from "lit-element";
import { LitElement, customElement, property, html, css, TemplateResult } from "lit-element";
import { HomeAssistant } from "custom-card-helpers";
import {
Route,
Status,
Configuration,
Repository,
LovelaceResource,
} from "../data/common";
import { Route, Status, Configuration, Repository, LovelaceResource } from "../data/common";
import { localize } from "../localize/localize";
import { settingsClearAllNewRepositories } from "../data/websocket";

import { sections } from "../panels/hacs-sections";

@customElement("hacs-tabbed-menu")
export class HacsTabbedMenu extends LitElement {
@property({ attribute: false }) public configuration: Configuration;
Expand All @@ -35,10 +24,7 @@ export class HacsTabbedMenu extends LitElement {
vertical-offset="40"
close-on-activate
>
<ha-icon-button
icon="hass:dots-vertical"
slot="dropdown-trigger"
></ha-icon-button>
<ha-icon-button icon="hass:dots-vertical" slot="dropdown-trigger"></ha-icon-button>
<paper-listbox slot="dropdown-content">
<hacs-link url="https://hacs.xyz/"
><paper-item>${localize("menu.documentation")}</paper-item></hacs-link
Expand All @@ -52,9 +38,7 @@ export class HacsTabbedMenu extends LitElement {
>`
: ""}
<hacs-link url="https://github.com/hacs"
><paper-item>GitHub</paper-item></hacs-link
>
<hacs-link url="https://github.com/hacs"><paper-item>GitHub</paper-item></hacs-link>
<hacs-link url="https://hacs.xyz/docs/issues"
><paper-item>${localize("menu.open_issue")}</paper-item></hacs-link
>
Expand All @@ -64,15 +48,14 @@ export class HacsTabbedMenu extends LitElement {
>`
: ""}
<paper-item @click=${this._showAboutDialog}
>${localize("menu.about")}</paper-item
>
<paper-item @click=${this._showAboutDialog}>${localize("menu.about")}</paper-item>
</paper-listbox>
</paper-menu-button>`;
}

private async _clearAllNewRepositories() {
await settingsClearAllNewRepositories(this.hass);
const section = sections.panels.find((s) => s.id === this.route.path.replace("/", ""));
await settingsClearAllNewRepositories(this.hass, section.categories);
}

private _showAboutDialog() {
Expand Down
60 changes: 16 additions & 44 deletions src/data/websocket.ts
Expand Up @@ -36,32 +36,23 @@ export const getStatus = async (hass: HomeAssistant) => {
return response;
};

export const repositoryInstall = async (
hass: HomeAssistant,
repository: string
) => {
export const repositoryInstall = async (hass: HomeAssistant, repository: string) => {
await hass.connection.sendMessagePromise<void>({
type: "hacs/repository",
action: "install",
repository: repository,
});
};

export const repositoryUninstall = async (
hass: HomeAssistant,
repository: string
) => {
export const repositoryUninstall = async (hass: HomeAssistant, repository: string) => {
await hass.connection.sendMessagePromise<void>({
type: "hacs/repository",
action: "uninstall",
repository: repository,
});
};

export const repositoryToggleBeta = async (
hass: HomeAssistant,
repository: string
) => {
export const repositoryToggleBeta = async (hass: HomeAssistant, repository: string) => {
await hass.connection.sendMessagePromise<void>({
type: "hacs/repository",
action: "toggle_beta",
Expand Down Expand Up @@ -95,11 +86,7 @@ export const repositorySetVersion = async (
});
};

export const repositoryAdd = async (
hass: HomeAssistant,
repository: string,
category: string
) => {
export const repositoryAdd = async (hass: HomeAssistant, repository: string, category: string) => {
await hass.connection.sendMessagePromise<void>({
type: "hacs/repository/data",
action: "add",
Expand All @@ -108,51 +95,44 @@ export const repositoryAdd = async (
});
};

export const repositorySetNotNew = async (
hass: HomeAssistant,
repository: string
) => {
export const repositorySetNotNew = async (hass: HomeAssistant, repository: string) => {
await hass.connection.sendMessagePromise<void>({
type: "hacs/repository",
action: "not_new",
repository: repository,
});
};

export const repositoryUpdate = async (
hass: HomeAssistant,
repository: string
) => {
export const repositoryUpdate = async (hass: HomeAssistant, repository: string) => {
await hass.connection.sendMessagePromise<void>({
type: "hacs/repository",
action: "update",
repository: repository,
});
};

export const repositoryDelete = async (
hass: HomeAssistant,
repository: string
) => {
export const repositoryDelete = async (hass: HomeAssistant, repository: string) => {
await hass.connection.sendMessagePromise<void>({
type: "hacs/repository",
action: "delete",
repository: repository,
});
};

export const settingsClearAllNewRepositories = async (hass: HomeAssistant) => {
export const settingsClearAllNewRepositories = async (
hass: HomeAssistant,
categories: string[]
) => {
await hass.connection.sendMessagePromise<void>({
type: "hacs/settings",
action: "clear_new",
categories,
});
};

export const getLovelaceConfiguration = async (hass: HomeAssistant) => {
try {
const response = await hass.connection.sendMessagePromise<
LovelaceResource[]
>({
const response = await hass.connection.sendMessagePromise<LovelaceResource[]>({
type: "lovelace/resources",
});
return response;
Expand All @@ -161,26 +141,18 @@ export const getLovelaceConfiguration = async (hass: HomeAssistant) => {
}
};

export const fetchResources = (
hass: HomeAssistant
): Promise<LovelaceResource[]> =>
export const fetchResources = (hass: HomeAssistant): Promise<LovelaceResource[]> =>
hass.connection.sendMessagePromise({
type: "lovelace/resources",
});

export const createResource = (
hass: HomeAssistant,
values: LovelaceResourcesMutableParams
) =>
export const createResource = (hass: HomeAssistant, values: LovelaceResourcesMutableParams) =>
hass.callWS<LovelaceResource>({
type: "lovelace/resources/create",
...values,
});

export const updateResource = (
hass: HomeAssistant,
values: LovelaceResourcesMutableParams
) =>
export const updateResource = (hass: HomeAssistant, values: LovelaceResourcesMutableParams) =>
hass.callWS<LovelaceResource>({
type: "lovelace/resources/update",
...values,
Expand Down

0 comments on commit 0095cff

Please sign in to comment.