Skip to content
Open
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
2 changes: 2 additions & 0 deletions custom_components/sonoff/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def spec(cls, base: str = None, enabled: bool = None, **kwargs) -> type:
XSwitch,
LED,
RSSI,
PULSE,
XPulseWidth,
spec(XSensor, param="current"),
spec(XSensor, param="power"),
spec(XSensor, param="voltage"),
Expand Down
6 changes: 4 additions & 2 deletions custom_components/sonoff/number.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from homeassistant.components.number import NumberEntity, NumberMode
from homeassistant.const import UnitOfTemperature
from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode
from homeassistant.const import UnitOfTemperature, UnitOfTime

from .core.const import DOMAIN
from .core.entity import XEntity
Expand Down Expand Up @@ -39,11 +39,13 @@ async def async_set_native_value(self, value: float) -> None:
class XPulseWidth(XNumber):
param = "pulseWidth"

_attr_device_class = NumberDeviceClass.DURATION
_attr_entity_registry_enabled_default = False

_attr_native_max_value = 36000
_attr_native_min_value = 0.5
_attr_native_step = 0.5
_attr_native_unit_of_measurement = UnitOfTime.SECONDS

def set_state(self, params: dict):
self._attr_native_value = params["pulseWidth"] / 1000
Expand Down
12 changes: 12 additions & 0 deletions tests/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ColorMode,
LightEntity,
)
from homeassistant.components.number import NumberDeviceClass
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
from homeassistant.components.switch import SwitchEntity
from homeassistant.components.script import ATTR_LAST_TRIGGERED
Expand All @@ -17,6 +18,7 @@
MINOR_VERSION,
STATE_ON,
UnitOfEnergy,
UnitOfTime,
UnitOfVolume,
)
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC
Expand Down Expand Up @@ -566,6 +568,16 @@ def test_sonoff_pow():
power: XSensor = next(e for e in entities if e.uid == "current")
assert power.state == 1.23

pulse: XToggle = next(e for e in entities if e.uid == "pulse")
assert pulse.is_on is False
assert pulse.entity_registry_enabled_default is False

pulse_width = next(e for e in entities if isinstance(e, XPulseWidth))
assert pulse_width.native_value == 0.5
assert pulse_width.device_class == NumberDeviceClass.DURATION
assert pulse_width.native_unit_of_measurement == UnitOfTime.SECONDS
assert pulse_width.entity_registry_enabled_default is False


def test_rfbridge():
logger_warning = []
Expand Down