2 * Copyright (c) 2010-2022 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.automation.pwm.internal.handler.state;
15 import java.util.concurrent.ScheduledFuture;
16 import java.util.concurrent.TimeUnit;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
21 * Active when, the PWM period ended with a duty cycle set to 0%.
23 * @author Fabian Wolter - Initial Contribution
26 public class DutycycleZeroState extends State {
27 private ScheduledFuture<?> periodTimer;
29 public DutycycleZeroState(StateMachine context) {
34 periodTimer = scheduler.schedule(this::periodEnded, context.getPeriodMs(), TimeUnit.MILLISECONDS);
37 private void periodEnded() {
38 long dutycycleRounded = Math.round(context.getDutycycle());
40 if (dutycycleRounded <= 0) {
41 nextState(AlwaysOffState::new);
42 } else if (dutycycleRounded >= 100) {
43 nextState(DutycycleHundredState::new);
45 nextState(OnState::new);
50 public void dutyCycleChanged() {
55 protected void dutyCycleUpdated() {
60 public void dispose() {
61 periodTimer.cancel(false);