Other functionalities must be configured manually in code editor
367 |references to https://github.com/madmicio/LG-WebOS-Remote-Control
368 | 377 | `; 378 | } 379 | 380 | static get styles() { 381 | return css` 382 | 383 | .color-selector { 384 | display: grid; 385 | grid-template-columns: auto 8ch 3ch; 386 | width: 40ch; 387 | } 388 | 389 | .color-item { 390 | padding: .6em; 391 | font-size: 1em; 392 | } 393 | 394 | .heading { 395 | font-weight: bold; 396 | } 397 | 398 | .select-item { 399 | background-color: var(--label-badge-text-color); 400 | width: 40ch; 401 | padding: .6em; 402 | font-size: 1em; 403 | } 404 | 405 | `; 406 | } 407 | 408 | } 409 | -------------------------------------------------------------------------------- /src/icons.ts: -------------------------------------------------------------------------------- 1 | import { html } from "lit"; 2 | 3 | export function disneyIcon() { 4 | return html` 24 | `; 25 | } 26 | 27 | export function daznIcon() { 28 | return html` 52 | `; 53 | } 54 | 55 | export function nowTvIcon() { 56 | return html` 57 | 80 | `; 81 | } 82 | 83 | export function tvOpticIcon() { 84 | return html` 116 | `; 117 | } 118 | 119 | export function tvHeadphonesIcon() { 120 | return html` 121 | `; 140 | } 141 | 142 | export function opticIcon() { 143 | return html` 167 | `; 168 | } 169 | 170 | export function arcIcon() { 171 | return html``; 190 | } 191 | 192 | export function amazonIcon() { 193 | return html``; 240 | } 241 | 242 | export function lineOutIcon() { 243 | return html` 244 | 267 | `; 268 | } -------------------------------------------------------------------------------- /src/lg-remote-control.ts: -------------------------------------------------------------------------------- 1 | import { css, html, LitElement } from 'lit'; 2 | import { customElement } from 'lit/decorators.js'; 3 | import { HomeAssistant } from 'custom-card-helpers'; 4 | 5 | import "./editor"; 6 | import { lineOutIcon, amazonIcon, tvOpticIcon, daznIcon, disneyIcon, tvHeadphonesIcon, arcIcon, opticIcon, nowTvIcon } from "./icons"; 7 | import { HomeAssistantFixed, WindowWithCards } from "./types"; 8 | import { CARD_TAG_NAME, CARD_VERSION, EDITOR_CARD_TAG_NAME } from "./const"; 9 | import { getMediaPlayerEntitiesByPlatform } from "./utils"; 10 | 11 | 12 | const line1 = ' LG WebOS Remote Control Card '; 13 | const line2 = ` version: ${CARD_VERSION} `; 14 | /* eslint no-console: 0 */ 15 | console.info( 16 | `%c${line1}\n%c${line2}`, 17 | 'color: orange; font-weight: bold; background: black', 18 | 'color: white; font-weight: bold; background: dimgray', 19 | ); 20 | 21 | 22 | // Allow this card to appear in the card chooser menu 23 | const windowWithCards = window as unknown as WindowWithCards; 24 | windowWithCards.customCards = windowWithCards.customCards || []; 25 | windowWithCards.customCards.push({ 26 | type: CARD_TAG_NAME, 27 | name: "LG WebOS Remote Control Card", 28 | preview: true, 29 | description: "Remote control card for LG WebOS TV devices" 30 | }); 31 | 32 | 33 | 34 | @customElement(CARD_TAG_NAME) 35 | class LgRemoteControl extends LitElement { 36 | 37 | public hass!: HomeAssistant; 38 | public config!: any; 39 | private _show_inputs: boolean; 40 | private _show_sound_output: boolean; 41 | private _show_text: boolean; 42 | private _show_keypad: boolean; 43 | private _show_vol_text: boolean; 44 | private volume_value: number; 45 | private soundOutput: string; 46 | private output_entity: string; 47 | private valueDisplayTimeout: NodeJS.Timeout; 48 | private homeisLongPress: boolean = false; 49 | private homelongPressTimer: any; // Tipo generico, ma puoi specificare il tipo corretto se lo conosci 50 | 51 | 52 | static getConfigElement() { 53 | // Create and return an editor element 54 | return document.createElement(EDITOR_CARD_TAG_NAME); 55 | } 56 | 57 | public static getStubConfig(hass: HomeAssistantFixed) { 58 | let entities = getMediaPlayerEntitiesByPlatform(hass, "webostv"); 59 | if(entities.length == 0){ 60 | entities = Object.keys(hass.entities).filter(e => e.startsWith("media_player.")); 61 | } 62 | const entity = entities.length > 0 ? entities[0] : "media_player.lg_webos_smart_tv"; 63 | return { 64 | "type": `custom:${CARD_TAG_NAME}`, 65 | "entity": entity 66 | } 67 | } 68 | 69 | static get iconMapping() { 70 | return { 71 | "disney": disneyIcon(), 72 | "dazn": daznIcon(), 73 | "nowtv": nowTvIcon(), 74 | "amazon": amazonIcon(), 75 | }; 76 | } 77 | 78 | static get properties() { 79 | return { 80 | hass: {}, 81 | config: {}, 82 | _show_inputs: {}, 83 | _show_sound_output: {}, 84 | _show_text: {}, 85 | _show_keypad: {}, 86 | _show_vol_text: {}, 87 | volume_value: { type: Number, reflect: true }, 88 | output_entity: { type: Number, reflect: true }, 89 | 90 | }; 91 | } 92 | 93 | constructor() { 94 | super(); 95 | this._show_inputs = false; 96 | this._show_sound_output = false; 97 | this._show_text = false; 98 | this._show_keypad = false; 99 | this._show_vol_text = false; 100 | this.volume_value = 0; 101 | this.soundOutput = ""; 102 | 103 | } 104 | 105 | render() { 106 | const stateObj = this.hass.states[this.config.entity]; 107 | const colorButtons = this.config.color_buttons; 108 | 109 | const borderWidth = this.config.dimensions && this.config.dimensions.border_width ? this.config.dimensions.border_width : "1px"; 110 | const scale = this.config.dimensions && this.config.dimensions.scale ? this.config.dimensions.scale : 1; 111 | const remoteWidth = Math.round(scale * 260) + "px"; 112 | const tv_name_color = this.config.tv_name_color ? this.config.tv_name_color : "var(--primary-text-color)"; 113 | const backgroundColor = this.config.colors && this.config.colors.background ? this.config.colors.background : "var( --ha-card-background, var(--card-background-color, white) )"; 114 | const borderColor = this.config.colors && this.config.colors.border ? this.config.colors.border: "var(--primary-text-color)"; 115 | const buttonColor = this.config.colors && this.config.colors.buttons ? this.config.colors.buttons : "var(--secondary-background-color)"; 116 | const textColor = this.config.colors && this.config.colors.text ? this.config.colors.text : "var(--primary-text-color)"; 117 | const mac = this.config.mac; 118 | 119 | if (this.config.ampli_entity && 120 | (this.hass.states[this.config.entity].attributes.sound_output === 'external_arc' || 121 | this.hass.states[this.config.entity].attributes.sound_output === 'external_optical')) { 122 | 123 | this.volume_value = Math.round(this.hass.states[this.config.ampli_entity].attributes.volume_level * 100 * 2) / 2; 124 | this.output_entity = this.config.ampli_entity; 125 | 126 | } else { 127 | 128 | this.volume_value = Math.round(this.hass.states[this.config.entity].attributes.volume_level * 100); 129 | this.output_entity = this.config.entity; 130 | } 131 | 132 | return html` 133 |SOURCE
155 |