Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbgroup committed Dec 22, 2023
2 parents f1a51a2 + 43cd706 commit 26761b5
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 73 deletions.
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 1.2.0

- filters for the album types applied before the query (primary and secondary types)

## 1.1.4

- Code cleanup
- Handle some errors

## 1.1.3

- bug in the layout
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "kodi-musicbrainz-card",
"version": "1.1.3",
"version": "1.2.0",
"description": "Kodi MusicBrainz Card",
"keywords": [
"home-assistant",
Expand All @@ -15,6 +15,7 @@
"author": "Gautier Vanderslyen <gautier.vanderslyen@gmail.com>",
"license": "MIT",
"dependencies": {
"@material/mwc-checkbox": "^0.3.6",
"change-perspective": "^1.0.1",
"compare-versions": "^4.0.1",
"custom-card-helpers": "^1.9.0",
Expand Down Expand Up @@ -52,4 +53,3 @@
"rollup": "rollup -c"
}
}

17 changes: 16 additions & 1 deletion src/const.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
export const CARD_VERSION = "1.1.3";
export const CARD_VERSION = "1.2.0";

export const DEFAULT_ENTITY_NAME = "sensor.kodi_media_sensor_playlist";
export const RESULT_ARTISTS = 1;
export const RESULT_RELEASEGROUPS = 2;

export const PRIMARYY_TYPES = {
Album: { id: "filter_primaryType_album", editor_label: "Include primary type Album", mb_query:"album"},
Single: { id: "filter_primaryType_single", editor_label: "Include primary type Single", mb_query:"single" },
Broadcast: { id: "filter_primaryType_broadcast", editor_label: "Include primary type Broadcast" , mb_query:"broadcast"},
EP: { id: "filter_primaryType_ep", editor_label: "Include primary type EP", mb_query:"ep" },
Other: { id: "filter_primaryType_other", editor_label: "Include primary type Other" , mb_query:"dj-mix"},
};
export const SECONDARY_TYPES = {
Demo: { id: "filter_secondaryType_demo", editor_label: "Include secondary type Demo", mb_query:"demo" },
Live: { id: "filter_secondaryType_live", editor_label: "Include secondary type Live", mb_query:"live" },
Soundtrack: { id: "filter_secondaryType_soundtrack", editor_label: "Include secondary type Soundtrack", mb_query:"soundtrack" },
Compilation: { id: "filter_secondaryType_compilation", editor_label: "Include secondary type Compilation", mb_query:"compilation" },
Remix: { id: "filter_secondaryType_remix", editor_label: "Include secondary type Remix" , mb_query:"remix"},
DJ_Mix: { id: "filter_secondaryType_djmix", editor_label: "Include secondary type DJ-Mix" , mb_query:"dj-mix"},
};
44 changes: 44 additions & 0 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
import { customElement, property, state } from "lit/decorators";
import { fireEvent, HomeAssistant, LovelaceCardEditor } from "custom-card-helpers";

import { PRIMARYY_TYPES, SECONDARY_TYPES } from "./const";

import { KodiMusicBrainzCardConfig } from "./types";

@customElement("kodi-musicbrainz-card-editor")
Expand Down Expand Up @@ -37,6 +39,13 @@ export class KodiMusicBrainzCardEditor extends LitElement implements LovelaceCar
return this._config?.show_version || false;
}

get _filter_primaryType_album(): boolean {
return this._config?.filter_primaryType_album || false;
}
get _filter_primaryType_single(): boolean {
return this._config?.filter_primaryType_single || false;
}

protected render(): TemplateResult | void {
if (!this.hass || !this._helpers) {
return html``;
Expand Down Expand Up @@ -79,10 +88,44 @@ export class KodiMusicBrainzCardEditor extends LitElement implements LovelaceCar
@change=${this._valueChanged}></ha-switch>
</ha-formfield>
</div>
${this.createPrimaryTypesEl()}
${this.createSecondaryTypesEl()}
</div>
`;
}

private createTypeEl(typeValue){
const selected = this._config?.[typeValue.id];
selected == undefined ? false : selected;

return html`<div class="config">
<ha-formfield class="switch-wrapper" label="${typeValue.editor_label}"
><ha-switch
.checked="${selected}"
@change=${this._valueChanged}
.configValue="${typeValue.id}"></ha-switch
></ha-formfield>
</div>`
}

private createSecondaryTypesEl() {
const itemTemplates: TemplateResult[] = [];
for (const key of Object.keys(SECONDARY_TYPES)) {
itemTemplates.push(this.createTypeEl(SECONDARY_TYPES[key]));
}
return itemTemplates;
}


private createPrimaryTypesEl() {
const itemTemplates: TemplateResult[] = [];
for (const key of Object.keys(PRIMARYY_TYPES)) {
itemTemplates.push(this.createTypeEl(PRIMARYY_TYPES[key]));
}
return itemTemplates;
}

private _initialize(): void {
if (this.hass === undefined) return;
if (this._config === undefined) return;
Expand All @@ -95,6 +138,7 @@ export class KodiMusicBrainzCardEditor extends LitElement implements LovelaceCar
}

private _valueChanged(ev): void {
console.debug(this._config);
if (!this._config || !this.hass) {
return;
}
Expand Down
Loading

0 comments on commit 26761b5

Please sign in to comment.