Skip to content

Commit

Permalink
Merge pull request #103 from matt8707/light
Browse files Browse the repository at this point in the history
Add onoff light, closes #65
  • Loading branch information
matt8707 authored Jan 6, 2024
2 parents 6c7c65d + fbc9ab4 commit e8158cd
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions src/lib/Modal/LightModal.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script lang="ts">
import { states, selectedLanguage, lang, ripple } from '$lib/Stores';
import { states, selectedLanguage, lang, ripple, connection } from '$lib/Stores';
import Modal from '$lib/Modal/Index.svelte';
import LightSlider from '$lib/Components/LightSlider.svelte';
import ColorPicker from '$lib/Components/ColorPicker.svelte';
import ConfigButtons from '$lib/Modal/ConfigButtons.svelte';
import Ripple from 'svelte-ripple';
import { getName } from '$lib/Utils';
import type { HassEntity } from 'home-assistant-js-websocket';
import { callService, type HassEntity } from 'home-assistant-js-websocket';
import Toggle from '$lib/Components/Toggle.svelte';
export let isOpen: boolean;
export let sel: any;
Expand Down Expand Up @@ -34,10 +35,18 @@
xy: $lang('color')
};
// color
$: supportedColorModes = entity?.attributes?.supported_color_modes?.filter(
(m: string) => m !== 'brightness'
);
//color
let supportedColorModes: string | any[] = [];
$: toggle = entity?.state === 'on';
$: colorModes = entity?.attributes?.supported_color_modes;
$: if (Array.isArray(colorModes)) {
supportedColorModes = colorModes.filter((m) => m !== 'brightness');
} else if (typeof colorModes === 'string') {
if (colorModes !== 'brightness') {
supportedColorModes = [colorModes];
}
}
$: colorMode = entity?.attributes?.color_mode;
$: selTab = supportMappings?.[colorMode];
Expand All @@ -49,6 +58,15 @@
if (masterEntity?.entity_id) {
groupSelected = $states?.[masterEntity.entity_id]?.entity_id;
}
/**
* Calls light.toggle service
*/
function handleClick() {
callService($connection, 'light', 'toggle', {
entity_id: entity?.entity_id
});
}
</script>

{#if isOpen}
Expand Down Expand Up @@ -90,6 +108,13 @@
</div>
{/if}

<!-- ONOFF -->
{#if supportedColorModes?.includes('onoff')}
<h2>{$lang('toggle')}</h2>

<Toggle bind:checked={toggle} on:change={handleClick} />
{/if}

<!-- BRIGHTNESS -->
{#if brightness !== undefined}
<h2>
Expand Down

0 comments on commit e8158cd

Please sign in to comment.