Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# ==================== FAN ====================
@attr.s
class FanInfo(EntityInfo):
supports_oscillation = attr.ib(type=bool, default=False)
supports_speed = attr.ib(type=bool, default=False)
class FanSpeed(enum.IntEnum):
LOW = 0
MEDIUM = 1
HIGH = 2
@attr.s
class FanState(EntityState):
state = attr.ib(type=bool, default=False)
oscillating = attr.ib(type=bool, default=False)
speed = attr.ib(type=FanSpeed, converter=FanSpeed, default=FanSpeed.LOW)
# ==================== LIGHT ====================
@attr.s
class LightInfo(EntityInfo):
supports_brightness = attr.ib(type=bool, default=False)
supports_rgb = attr.ib(type=bool, default=False)
supports_white_value = attr.ib(type=bool, default=False)
supports_color_temperature = attr.ib(type=bool, default=False)
min_mireds = attr.ib(type=float, default=0.0)
max_mireds = attr.ib(type=float, default=0.0)
effects = attr.ib(type=List[str], converter=list, factory=list)
# ==================== LIGHT ====================
@attr.s
class LightInfo(EntityInfo):
supports_brightness = attr.ib(type=bool, default=False)
supports_rgb = attr.ib(type=bool, default=False)
supports_white_value = attr.ib(type=bool, default=False)
supports_color_temperature = attr.ib(type=bool, default=False)
min_mireds = attr.ib(type=float, default=0.0)
max_mireds = attr.ib(type=float, default=0.0)
effects = attr.ib(type=List[str], converter=list, factory=list)
@attr.s
class LightState(EntityState):
state = attr.ib(type=bool, default=False)
brightness = attr.ib(type=float, default=0.0)
red = attr.ib(type=float, default=0.0)
green = attr.ib(type=float, default=0.0)
blue = attr.ib(type=float, default=0.0)
white = attr.ib(type=float, default=0.0)
color_temperature = attr.ib(type=float, default=0.0)
effect = attr.ib(type=str, default='')
# ==================== SENSOR ====================
@attr.s
class SensorInfo(EntityInfo):
icon = attr.ib(type=str, default='')
unit_of_measurement = attr.ib(type=str, default='')
accuracy_decimals = attr.ib(type=int, default=0)
@attr.s
class EntityState:
key = attr.ib(type=int, default=0)
# ==================== BINARY SENSOR ====================
@attr.s
class BinarySensorInfo(EntityInfo):
device_class = attr.ib(type=str, default='')
is_status_binary_sensor = attr.ib(type=bool, default=False)
@attr.s
class BinarySensorState(EntityState):
state = attr.ib(type=bool, default=False)
missing_state = attr.ib(type=bool, default=False)
# ==================== COVER ====================
@attr.s
class CoverInfo(EntityInfo):
assumed_state = attr.ib(type=bool, default=False)
supports_position = attr.ib(type=bool, default=False)
supports_tilt = attr.ib(type=bool, default=False)
device_class = attr.ib(type=str, default='')
class LegacyCoverState(enum.IntEnum):
OPEN = 0
CLOSED = 1
@attr.s
class SensorState(EntityState):
state = attr.ib(type=float, default=0.0)
missing_state = attr.ib(type=bool, default=False)
# ==================== SWITCH ====================
@attr.s
class SwitchInfo(EntityInfo):
icon = attr.ib(type=str, default='')
assumed_state = attr.ib(type=bool, default=False)
@attr.s
class SwitchState(EntityState):
state = attr.ib(type=bool, default=False)
# ==================== TEXT SENSOR ====================
@attr.s
class TextSensorInfo(EntityInfo):
icon = attr.ib(type=str, default='')
@attr.s
class TextSensorState(EntityState):
state = attr.ib(type=str, default='')
missing_state = attr.ib(type=bool, default=False)
# ==================== CAMERA ====================
white = attr.ib(type=float, default=0.0)
color_temperature = attr.ib(type=float, default=0.0)
effect = attr.ib(type=str, default='')
# ==================== SENSOR ====================
@attr.s
class SensorInfo(EntityInfo):
icon = attr.ib(type=str, default='')
unit_of_measurement = attr.ib(type=str, default='')
accuracy_decimals = attr.ib(type=int, default=0)
force_update = attr.ib(type=bool, default=False)
@attr.s
class SensorState(EntityState):
state = attr.ib(type=float, default=0.0)
missing_state = attr.ib(type=bool, default=False)
# ==================== SWITCH ====================
@attr.s
class SwitchInfo(EntityInfo):
icon = attr.ib(type=str, default='')
assumed_state = attr.ib(type=bool, default=False)
@attr.s
class SwitchState(EntityState):
state = attr.ib(type=bool, default=False)
class LegacyCoverCommand(enum.IntEnum):
OPEN = 0
CLOSE = 1
STOP = 2
class CoverOperation(enum.IntEnum):
IDLE = 0
IS_OPENING = 1
IS_CLOSING = 2
@attr.s
class CoverState(EntityState):
legacy_state = attr.ib(type=LegacyCoverState, converter=LegacyCoverState,
default=LegacyCoverState.OPEN)
position = attr.ib(type=float, default=0.0)
tilt = attr.ib(type=float, default=0.0)
current_operation = attr.ib(type=CoverOperation, converter=CoverOperation,
default=CoverOperation.IDLE)
def is_closed(self, api_version: APIVersion):
if api_version >= APIVersion(1, 1):
return self.position == 0.0
return self.legacy_state == LegacyCoverState.CLOSED
# ==================== FAN ====================
@attr.s
class FanInfo(EntityInfo):
@attr.s
class TextSensorState(EntityState):
state = attr.ib(type=str, default='')
missing_state = attr.ib(type=bool, default=False)
# ==================== CAMERA ====================
@attr.s
class CameraInfo(EntityInfo):
pass
@attr.s
class CameraState(EntityState):
image = attr.ib(type=bytes, factory=bytes)
# ==================== CLIMATE ====================
class ClimateMode(enum.IntEnum):
OFF = 0
AUTO = 1
COOL = 2
HEAT = 3
FAN_ONLY = 4
DRY = 5
class ClimateFanMode(enum.IntEnum):
ON = 0
OFF = 1
factory=list)
visual_min_temperature = attr.ib(type=float, default=0.0)
visual_max_temperature = attr.ib(type=float, default=0.0)
visual_temperature_step = attr.ib(type=float, default=0.0)
supports_away = attr.ib(type=bool, default=False)
supports_action = attr.ib(type=bool, default=False)
supported_fan_modes = attr.ib(
type=List[ClimateFanMode], converter=_convert_climate_fan_modes, factory=list
)
supported_swing_modes = attr.ib(
type=List[ClimateSwingMode], converter=_convert_climate_swing_modes, factory=list
)
@attr.s
class ClimateState(EntityState):
mode = attr.ib(type=ClimateMode, converter=ClimateMode,
default=ClimateMode.OFF)
action = attr.ib(type=ClimateAction, converter=ClimateAction,
default=ClimateAction.OFF)
current_temperature = attr.ib(type=float, default=0.0)
target_temperature = attr.ib(type=float, default=0.0)
target_temperature_low = attr.ib(type=float, default=0.0)
target_temperature_high = attr.ib(type=float, default=0.0)
away = attr.ib(type=bool, default=False)
fan_mode = attr.ib(
type=ClimateFanMode, converter=ClimateFanMode, default=ClimateFanMode.AUTO
)
swing_mode = attr.ib(
type=ClimateSwingMode, converter=ClimateSwingMode, default=ClimateSwingMode.OFF
)
assumed_state = attr.ib(type=bool, default=False)
@attr.s
class SwitchState(EntityState):
state = attr.ib(type=bool, default=False)
# ==================== TEXT SENSOR ====================
@attr.s
class TextSensorInfo(EntityInfo):
icon = attr.ib(type=str, default='')
@attr.s
class TextSensorState(EntityState):
state = attr.ib(type=str, default='')
missing_state = attr.ib(type=bool, default=False)
# ==================== CAMERA ====================
@attr.s
class CameraInfo(EntityInfo):
pass
@attr.s
class CameraState(EntityState):
image = attr.ib(type=bytes, factory=bytes)
# ==================== CLIMATE ====================