Skip to content

Commit

Permalink
Properly hide CCT automation features when CCT control is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphiiko committed Jul 5, 2024
1 parent 49eb499 commit b30d452
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="label" *ngIf="config">
<div class="colortemp-container" @hshrink *ngIf="config?.changeColorTemperature">
<div class="colortemp-container" @hshrink *ngIf="config?.changeColorTemperature && cctControlEnabled">
<div class="colortemp-icon" [style.background-color]="getCSSColorForCCT(config.colorTemperature)"></div>
<span>{{ config.colorTemperature }} K</span>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { hshrink, vshrink } from '../../../../../../../utils/animations';
})
export class BrightnessAutomationConfigLabelComponent {
@Input() public advancedMode = false;
@Input() public cctControlEnabled = false;
@Input() public config?: BrightnessEventAutomationConfig;
protected readonly getCSSColorForCCT = getCSSColorForCCT;
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ <h3 translate>brightness-automations.brightnessAutomations.changeBrightness.cate
</div>
</div>
</div>
<div class="setting-category">
<div class="setting-category" *ngIf="cctControlEnabled()">
<div class="setting-category-title-row">
<h3 translate>brightness-automations.brightnessAutomations.changeTemperature.category</h3>
<span class="warning-icon" [tooltip]="'brightness-automations.brightnessAutomations.changeTemperature.warning'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
import { HardwareBrightnessControlService } from '../../../../../../../services/brightness-control/hardware-brightness-control.service';
import { SimpleBrightnessControlService } from '../../../../../../../services/brightness-control/simple-brightness-control.service';
import { SoftwareBrightnessControlService } from '../../../../../../../services/brightness-control/software-brightness-control.service';
import { AppSettingsService } from '../../../../../../../services/app-settings.service';

interface BrightnessBounds {
min: number;
Expand All @@ -29,6 +30,7 @@ export class BrightnessAutomationDetailsComponent implements OnInit {
eventId = input.required<BrightnessEvent>();
advancedMode: Signal<boolean>;
config: Signal<BrightnessEventAutomationConfig>;
cctControlEnabled: Signal<boolean>;
protected brightnessBounds: Record<BrightnessType, BrightnessBounds> = {
SIMPLE: { min: 5, max: 100 },
SOFTWARE: { min: 5, max: 100 },
Expand All @@ -48,12 +50,17 @@ export class BrightnessAutomationDetailsComponent implements OnInit {
protected vshakeElements: string[] = [];

constructor(
private readonly automationConfigService: AutomationConfigService,
private automationConfigService: AutomationConfigService,
private simpleBrightnessControl: SimpleBrightnessControlService,
private softwareBrightnessControl: SoftwareBrightnessControlService,
private hardwareBrightnessControl: HardwareBrightnessControlService,
private appSettingsService: AppSettingsService,
private destroyRef: DestroyRef
) {
this.cctControlEnabled = toSignal(
this.appSettingsService.settings.pipe(map((s) => s.cctControlEnabled)),
{ initialValue: false }
);
const automationsConfig = toSignal(
this.automationConfigService.configs.pipe(map((c) => c.BRIGHTNESS_AUTOMATIONS))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ <h2 translate>brightness-automations.brightnessAutomations.events</h2>
<div class="small-spinner" @fade *ngIf="event.inProgress"></div>
<app-brightness-automation-config-label
[advancedMode]="config.advancedMode"
[cctControlEnabled]="cctControlEnabled"
[config]="config[event.name]"
(click)="editEvent.emit(event.name)"
></app-brightness-automation-config-label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { combineLatest, map } from 'rxjs';
import { BrightnessCctAutomationService } from '../../../../../../../services/brightness-cct-automation.service';
import { fade } from '../../../../../../../utils/animations';
import { AppSettingsService } from '../../../../../../../services/app-settings.service';

@Component({
selector: 'app-brightness-automations-list',
Expand All @@ -21,6 +22,7 @@ export class BrightnessAutomationsListComponent implements OnInit {
AUTOMATION_CONFIGS_DEFAULT.BRIGHTNESS_AUTOMATIONS
);
@Output() editEvent = new EventEmitter<BrightnessEvent>();
protected cctControlEnabled = false;

protected events: Array<{
name: BrightnessEvent;
Expand All @@ -38,10 +40,16 @@ export class BrightnessAutomationsListComponent implements OnInit {
constructor(
private automationConfigService: AutomationConfigService,
private brightnessCctAutomations: BrightnessCctAutomationService,
private destroyRef: DestroyRef
private destroyRef: DestroyRef,
private appSettingsService: AppSettingsService
) {}

ngOnInit() {
this.appSettingsService.settings
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((settings) => {
this.cctControlEnabled = settings.cctControlEnabled;
});
this.events.forEach((event) => {
combineLatest([
this.brightnessCctAutomations.isBrightnessTransitionActive(event.name),
Expand Down

0 comments on commit b30d452

Please sign in to comment.