Skip to content

Commit

Permalink
control fan rotation direction from the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
bwp91 committed Jan 24, 2025
1 parent 4e8289a commit 0a6c349
Show file tree
Hide file tree
Showing 38 changed files with 204 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Plugin developers:
- add lighting mode option for terminal and log widgets
- only available when the UI is already in light mode
- fix long press on mobile devices
- control fan rotation direction from the ui

### Other Changes

Expand Down
10 changes: 9 additions & 1 deletion ui/src/app/core/accessories/types/fan/fan.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
@if (!service.values.On) {
<img src="/assets/hap-icons/fan-off.svg" alt="Fan" class="accessory-img" />
} @if (service.values.On) {
<img src="/assets/hap-icons/fan-on.svg" alt="Fan" class="accessory-img spin" />
<img
src="/assets/hap-icons/fan-on.svg"
alt="Fan"
class="accessory-img"
[ngClass]="{
'spin': !hasRotationDirection || (hasRotationDirection && service.values.RotationDirection === 0),
'spin-counter': !hasRotationDirection || (hasRotationDirection && service.values.RotationDirection === 1),
}"
/>
}
<div class="accessory-label mt-auto">{{ service.customName || service.serviceName }}</div>
@if (!service.values.RotationSpeed || !service.values.On) {
Expand Down
4 changes: 4 additions & 0 deletions ui/src/app/core/accessories/types/fan/fan.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class FanComponent implements OnInit {

@Input() public service: ServiceTypeX
public rotationSpeedUnit = ''
public hasRotationDirection = false

constructor() {}

Expand All @@ -31,6 +32,9 @@ export class FanComponent implements OnInit {
if (RotationSpeed && RotationSpeed.unit === 'percentage') {
this.rotationSpeedUnit = '%'
}
if (this.service.serviceCharacteristics.find(c => c.type === 'RotationDirection')) {
this.hasRotationDirection = true
}
}

onClick() {
Expand Down
30 changes: 26 additions & 4 deletions ui/src/app/core/accessories/types/fan/fan.manage.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ <h5 class="modal-title" [innerText]="service.customName || service.serviceName">
</div>
<div class="modal-body text-center px-5">
<h5>
<strong>
{{ 'accessories.control.fan' | translate }} {{ (service.values.On ? 'accessories.control.on' :
'accessories.control.off') | translate }}
</strong>
{{ 'accessories.control.fan' | translate }} {{ (service.values.On ? 'accessories.control.on' :
'accessories.control.off') | translate }}
</h5>

<div class="btn-group-vertical d-flex justify-content-center mb-4 p-0" role="group" aria-label="Fan Mode Control">
Expand Down Expand Up @@ -47,6 +45,30 @@ <h5 class="mb-0">{{ 'accessories.control.rotation_speed' | translate }}</h5>
(ngModelChange)="onTargetRotationSpeedChange()"
>
</nouislider>
} @if (hasRotationDirection && targetMode) {
<h5 class="mt-4">{{ 'accessories.control.rotation_direction' | translate }}</h5>
<div
class="btn-group-vertical d-flex justify-content-center mb-4 p-0"
role="group"
aria-label="Fan Direction Control"
>
<button
type="button"
class="btn mb-0 mx-0 px-0 py-3"
(click)="setRotationDirection(0)"
[ngClass]="{ 'btn-primary': service.values.RotationDirection === 0, 'btn-elegant': service.values.RotationDirection !== 0 }"
>
{{ 'accessories.control.rotation_clockwise' | translate }}
</button>
<button
type="button"
class="btn mb-0 mx-0 px-0 py-3"
(click)="setRotationDirection(1)"
[ngClass]="{ 'btn-primary': service.values.RotationDirection === 1, 'btn-elegant': service.values.RotationDirection !== 1 }"
>
{{ 'accessories.control.rotation_c_clockwise' | translate }}
</button>
</div>
}
</div>
<div class="modal-footer"></div>
Expand Down
9 changes: 9 additions & 0 deletions ui/src/app/core/accessories/types/fan/fan.manage.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class FanManageComponent implements OnInit {
public targetMode: any
public targetRotationSpeed: any
public targetRotationSpeedChanged: Subject<string> = new Subject<string>()
public hasRotationDirection = false

constructor() {
this.targetRotationSpeedChanged
Expand All @@ -52,6 +53,10 @@ export class FanManageComponent implements OnInit {
this.targetMode = this.service.values.On

this.loadRotationSpeed()

if (this.service.serviceCharacteristics.find(c => c.type === 'RotationDirection')) {
this.hasRotationDirection = true
}
}

loadRotationSpeed() {
Expand Down Expand Up @@ -81,4 +86,8 @@ export class FanManageComponent implements OnInit {
onTargetRotationSpeedChange() {
this.targetRotationSpeedChanged.next(this.targetRotationSpeed.value)
}

setRotationDirection(value: number) {
this.service.getCharacteristic('RotationDirection').setValue(value)
}
}
10 changes: 9 additions & 1 deletion ui/src/app/core/accessories/types/fanv2/fanv2.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@
@if (!service.values.Active) {
<img src="/assets/hap-icons/fan-off.svg" alt="Fan" class="accessory-img" />
} @if (service.values.Active) {
<img src="/assets/hap-icons/fan-on.svg" alt="Fan" class="accessory-img spin" />
<img
src="/assets/hap-icons/fan-on.svg"
alt="Fan"
class="accessory-img"
[ngClass]="{
'spin': !hasRotationDirection || (hasRotationDirection && service.values.RotationDirection === 0),
'spin-counter': hasRotationDirection && service.values.RotationDirection === 1,
}"
/>
}
<div class="accessory-label mt-auto">{{ service.customName || service.serviceName }}</div>
@if (!service.values.RotationSpeed || !service.values.Active) {
Expand Down
4 changes: 4 additions & 0 deletions ui/src/app/core/accessories/types/fanv2/fanv2.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export class Fanv2Component implements OnInit {

@Input() public service: ServiceTypeX
public rotationSpeedUnit = ''
public hasRotationDirection = false

constructor() {}

Expand All @@ -31,6 +32,9 @@ export class Fanv2Component implements OnInit {
if (RotationSpeed && RotationSpeed.unit === 'percentage') {
this.rotationSpeedUnit = '%'
}
if (this.service.serviceCharacteristics.find(c => c.type === 'RotationDirection')) {
this.hasRotationDirection = true
}
}

onClick() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ <h5 class="modal-title" [innerText]="service.customName || service.serviceName">
</div>
<div class="modal-body text-center px-5">
<h5>
<strong>
{{ 'accessories.control.fan' | translate }} {{ (service.values.Active ? 'accessories.control.on' :
'accessories.control.off') | translate }}
</strong>
{{ 'accessories.control.fan' | translate }} {{ (service.values.Active ? 'accessories.control.on' :
'accessories.control.off') | translate }}
</h5>

<div class="btn-group-vertical d-flex justify-content-center mb-4 p-0" role="group" aria-label="Fan Mode Control">
Expand Down Expand Up @@ -47,6 +45,30 @@ <h5 class="mb-0">{{ 'accessories.control.rotation_speed' | translate }}</h5>
(ngModelChange)="onTargetRotationSpeedChange()"
>
</nouislider>
} @if (hasRotationDirection && targetMode === 1) {
<h5 class="mt-4">{{ 'accessories.control.rotation_direction' | translate }}</h5>
<div
class="btn-group-vertical d-flex justify-content-center mb-4 p-0"
role="group"
aria-label="Fan Direction Control"
>
<button
type="button"
class="btn mb-0 mx-0 px-0 py-3"
(click)="setRotationDirection(0)"
[ngClass]="{ 'btn-primary': service.values.RotationDirection === 0, 'btn-elegant': service.values.RotationDirection !== 0 }"
>
{{ 'accessories.control.rotation_clockwise' | translate }}
</button>
<button
type="button"
class="btn mb-0 mx-0 px-0 py-3"
(click)="setRotationDirection(1)"
[ngClass]="{ 'btn-primary': service.values.RotationDirection === 1, 'btn-elegant': service.values.RotationDirection !== 1 }"
>
{{ 'accessories.control.rotation_c_clockwise' | translate }}
</button>
</div>
}
</div>
<div class="modal-footer"></div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class Fanv2ManageComponent implements OnInit {
public targetMode: any
public targetRotationSpeed: any
public targetRotationSpeedChanged: Subject<string> = new Subject<string>()
public hasRotationDirection = false

constructor() {
this.targetRotationSpeedChanged
Expand All @@ -52,6 +53,10 @@ export class Fanv2ManageComponent implements OnInit {
this.targetMode = this.service.values.Active

this.loadRotationSpeed()

if (this.service.serviceCharacteristics.find(c => c.type === 'RotationDirection')) {
this.hasRotationDirection = true
}
}

loadRotationSpeed() {
Expand Down Expand Up @@ -81,4 +86,8 @@ export class Fanv2ManageComponent implements OnInit {
onTargetRotationSpeedChange() {
this.targetRotationSpeedChanged.next(this.targetRotationSpeed.value)
}

setRotationDirection(value: number) {
this.service.getCharacteristic('RotationDirection').setValue(value)
}
}
3 changes: 3 additions & 0 deletions ui/src/i18n/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Включено",
"accessories.control.open": "Отворено",
"accessories.control.opening": "Отваряне",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Скорост на въртене",
"accessories.control.running": "Running",
"accessories.control.speaker_volume": "Сила на звука",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Engegat",
"accessories.control.open": "Obert",
"accessories.control.opening": "Obrint",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Velocitat de rotació",
"accessories.control.running": "Funcionant",
"accessories.control.speaker_volume": "Volum",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Zapnuto",
"accessories.control.open": "Otevřeno",
"accessories.control.opening": "Otevírám",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Rychlost otáčení",
"accessories.control.running": "Spuštěný",
"accessories.control.speaker_volume": "Hlasitost",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "An",
"accessories.control.open": "Offen",
"accessories.control.opening": "Beim Öffnen",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Umdrehungsgeschwindigkeit",
"accessories.control.running": "Läuft",
"accessories.control.speaker_volume": "Lautstärke",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "On",
"accessories.control.open": "Open",
"accessories.control.opening": "Opening",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Rotation Speed",
"accessories.control.running": "Running",
"accessories.control.speaker_volume": "Volume",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Encendido",
"accessories.control.open": "Abierto",
"accessories.control.opening": "Abriendo",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Velocidad de rotación",
"accessories.control.running": "En funcionamiento",
"accessories.control.speaker_volume": "Volumen",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Päällä",
"accessories.control.open": "Auki",
"accessories.control.opening": "Avautuu",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Pyörimisnopeus",
"accessories.control.running": "Käynnissä",
"accessories.control.speaker_volume": "Äänenvoimakkuus",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "On",
"accessories.control.open": "Ouvert",
"accessories.control.opening": "Ouverture",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Vitesse de rotation",
"accessories.control.running": "En cours d'exécution",
"accessories.control.speaker_volume": "Volume",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "פועל",
"accessories.control.open": "פתח",
"accessories.control.opening": "פותח",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "מהירות סיבוב",
"accessories.control.running": "עובד",
"accessories.control.speaker_volume": "ווליום",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "On",
"accessories.control.open": "Open",
"accessories.control.opening": "Opening",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Rotation Speed",
"accessories.control.running": "Running",
"accessories.control.speaker_volume": "Hangerő",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Hidup",
"accessories.control.open": "Buka",
"accessories.control.opening": "Membuka",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Kecepatan Rotasi",
"accessories.control.running": "Berjalan",
"accessories.control.speaker_volume": "Volume",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Acceso",
"accessories.control.open": "Aperto",
"accessories.control.opening": "In apertura",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Velocità di rotazione",
"accessories.control.running": "In esecuzione",
"accessories.control.speaker_volume": "Volume",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "オン",
"accessories.control.open": "開放済み",
"accessories.control.opening": "開放中",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "回転速度",
"accessories.control.running": "稼働中",
"accessories.control.speaker_volume": "ボリューム",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "켜짐",
"accessories.control.open": "열림",
"accessories.control.opening": "여는 중",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "회전 속도",
"accessories.control.running": "실행 중",
"accessories.control.speaker_volume": "볼륨",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/mk.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Уклучено",
"accessories.control.open": "Отворено",
"accessories.control.opening": "Се отвора",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Брзина на вртење",
"accessories.control.running": "Се извршува",
"accessories.control.speaker_volume": "Јачина на звук",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "Aan",
"accessories.control.open": "Open",
"accessories.control.opening": "Aan het openen",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Draai snelheid",
"accessories.control.running": "Stromend",
"accessories.control.speaker_volume": "Volume",
Expand Down
3 changes: 3 additions & 0 deletions ui/src/i18n/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
"accessories.control.on": "",
"accessories.control.open": "Åpen",
"accessories.control.opening": "Åpner",
"accessories.control.rotation_c_clockwise": "Counter Clockwise",
"accessories.control.rotation_clockwise": "Clockwise",
"accessories.control.rotation_direction": "Rotation Direction",
"accessories.control.rotation_speed": "Rotasjonshastighet",
"accessories.control.running": "Running",
"accessories.control.speaker_volume": "Volum",
Expand Down
Loading

0 comments on commit 0a6c349

Please sign in to comment.