Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'valve' modal support, closes #152 #215

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 2 additions & 9 deletions PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ List grouped by domains and categorized based on their similar behaviors
- [x] <https://github.com/matt8707/ha-fusion/issues/24>
- [x] counter
- [x] group
- [x] valve
- [ ] lawn_mower

### Date

Expand All @@ -101,15 +103,6 @@ List grouped by domains and categorized based on their similar behaviors
- [x] zone
- [ ] idea: map with all persons?

### Untestable

- [ ] geo_location
- [ ] lawn_mower
- [ ] notify
- [ ] valve
- [ ] wake_word
- [ ] tts

## Object types

- [x] button
Expand Down
4 changes: 4 additions & 0 deletions src/lib/Components/ComputeIcon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@
? 'toggle-switch-variant'
: 'toggle-switch-variant-off'
: 'toggle-switch-variant',
valve:
stateObj?.attributes.device_class && stateObj?.attributes.device_class === 'gas'
? 'meter-gas'
: 'pipe-valve',
sensor:
stateObj?.attributes.device_class &&
stateObj?.attributes.device_class in FIXED_DEVICE_CLASS_ICONS
Expand Down
5 changes: 5 additions & 0 deletions src/lib/Main/Button.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@
openModal(() => import('$lib/Modal/VacuumModal.svelte'), { sel });
break;


case 'valve':
openModal(() => import('$lib/Modal/ValveModal.svelte'), { sel });
break;

case 'image':
openModal(() => import('$lib/Modal/ImageModal.svelte'), { sel });
break;
Expand Down
100 changes: 100 additions & 0 deletions src/lib/Modal/ValveModal.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<script lang="ts">
import { connection, lang, states, ripple } from '$lib/Stores';
import Modal from '$lib/Modal/Index.svelte';
import ConfigButtons from '$lib/Modal/ConfigButtons.svelte';
import { getName, getSupport } from '$lib/Utils';
import { callService } from 'home-assistant-js-websocket';
import Ripple from 'svelte-ripple';
import Icon from '@iconify/svelte';

export let isOpen: boolean;
export let sel: any;

$: entity = $states[sel?.entity_id];
$: state = entity?.state;
$: attributes = entity?.attributes;
$: supported_features = attributes?.supported_features;

$: supports = getSupport(supported_features, {
OPEN: 1,
CLOSE: 2,
SET_POSITION: 4,
STOP: 8
});

/**
* Handle click
*/
function handleClick(service: string) {
callService($connection, 'valve', service, {
entity_id: entity?.entity_id
});
}
</script>

{#if isOpen}
<Modal>
<h1 slot="title">{getName(sel, entity)}</h1>

<h2>{$lang('state')}</h2>

{$lang(state)}

<h2>{$lang('buttons')}</h2>

<div class="button-container">
{#if supports?.OPEN}
<button
title={$lang('open_valve')}
class:selected={entity?.state === 'open'}
on:click={() => handleClick('open_valve')}
use:Ripple={$ripple}
>
<div class="icon" style="transform: scale(0.7);">
<Icon icon="mdi:valve-open" height="none" />
</div>
</button>
{/if}

{#if supports?.CLOSE}
<button
title={$lang('close_valve')}
class:selected={entity?.state === 'closed'}
on:click={() => handleClick('close_valve')}
use:Ripple={$ripple}
>
<div class="icon" style="transform: scale(0.7);">
<Icon icon="mdi:valve-closed" height="none" />
</div>
</button>
{/if}

{#if supports?.STOP}
<button
title={$lang('stop_valve')}
on:click={() => handleClick('stop_valve')}
use:Ripple={$ripple}
>
<div class="icon">
<Icon icon="ic:round-stop" height="none" />
</div>
</button>
{/if}
</div>

<ConfigButtons />
</Modal>
{/if}

<style>
.button-container > button {
display: flex;
justify-content: center;
align-items: center;
}

.icon {
width: 1.6rem;
height: 1.6rem;
}
</style>