Class SmartPlugController

java.lang.Object
ru.gentoos.ehouse.controller.Controller
ru.gentoos.ehouse.controller.SmartPlugController
All Implemented Interfaces:
SmartPlug

public final class SmartPlugController extends Controller implements SmartPlug
Контроллер умной розетки Яндекс Умного дома (порт Controllers/smart_plug.py).

Получает состояние розетки (напряжение, ток, потребление) и управляет ей через Yandex IoT API c повторными попытками.

  • Constructor Summary

    Constructors
    Constructor
    Description
    SmartPlugController(String deviceId, String apiKey, int voltageRounding, int amperageRounding, int consumptionRounding, int stateRetryCount, int stateRetryDelay, HttpTransport transport, io.opentelemetry.api.trace.Tracer tracer)
    Инициализирует контроллер розетки.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    controlPlug(boolean turnOn)
    Включает/выключает розетку.
    Получает состояние розетки.
    Последнее полученное состояние.
    int
    Количество попыток получения состояния.
    int
    Пауза между попытками, сек.
     

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SmartPlugController

      public SmartPlugController(String deviceId, String apiKey, int voltageRounding, int amperageRounding, int consumptionRounding, int stateRetryCount, int stateRetryDelay, HttpTransport transport, io.opentelemetry.api.trace.Tracer tracer)
      Инициализирует контроллер розетки.
      Parameters:
      deviceId - идентификатор устройства
      apiKey - OAuth-токен Yandex IoT API
      voltageRounding - знаков для вольт
      amperageRounding - знаков для ампер
      consumptionRounding - знаков для ватт
      stateRetryCount - попыток получения состояния
      stateRetryDelay - пауза между попытками, сек.
      transport - HTTP-транспорт
      tracer - трейсер (может быть null)
  • Method Details

    • stateRetryCount

      public int stateRetryCount()
      Description copied from interface: SmartPlug
      Количество попыток получения состояния.
      Specified by:
      stateRetryCount in interface SmartPlug
    • stateRetryDelay

      public int stateRetryDelay()
      Description copied from interface: SmartPlug
      Пауза между попытками, сек.
      Specified by:
      stateRetryDelay in interface SmartPlug
    • state

      public Map<String,Object> state()
      Description copied from interface: SmartPlug
      Последнее полученное состояние.
      Specified by:
      state in interface SmartPlug
    • getState

      public Map<String,Object> getState()
      Description copied from interface: SmartPlug
      Получает состояние розетки.
      Specified by:
      getState in interface SmartPlug
      Returns:
      карта с ключами device_id, name, online, power, voltage, amperage, power_consumption (при полном отказе — значения по умолчанию)
    • controlPlug

      public boolean controlPlug(boolean turnOn)
      Description copied from interface: SmartPlug
      Включает/выключает розетку.
      Specified by:
      controlPlug in interface SmartPlug
      Parameters:
      turnOn - true — включить
      Returns:
      true при успехе
    • toString

      public String toString()
      Overrides:
      toString in class Object