API Documentation - Types
python library for accessing the openHAB REST API.
ColorType
Bases: CommandType
ColorType data_type class.
Source code in openhab/command_types.py
class ColorType(CommandType):
"""ColorType data_type class."""
TYPENAME = 'HSB'
SUPPORTED_TYPENAMES = [TYPENAME]
@classmethod
def parse(cls, value: str) -> typing.Optional[tuple[float, float, float]]:
"""Parse a given value."""
if value in ColorType.UNDEFINED_STATES:
return None
if not isinstance(value, str):
raise ValueError
str_split = value.split(',')
if len(str_split) != 3:
raise ValueError
hs, ss, bs = value.split(',', 3)
h = float(hs)
s = float(ss)
b = float(bs)
if not ((0 <= h <= 360) and (0 <= s <= 100) and (0 <= b <= 100)):
raise ValueError
return h, s, b
@classmethod
def validate(cls, value: typing.Union[str, tuple[float, float, float]]) -> None:
"""Value validation method.
Valid values are in format H,S,B.
Value ranges:
H(ue): 0-360
S(aturation): 0-100
B(rightness): 0-100
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if isinstance(value, str):
str_value = str(value)
elif isinstance(value, tuple) and len(value) == 3:
str_value = f'{value[0]},{value[1]},{value[2]}'
else:
raise ValueError
ColorType.parse(str_value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[tuple[float, float, float]]:
"""Parse a given value."""
if value in ColorType.UNDEFINED_STATES:
return None
if not isinstance(value, str):
raise ValueError
str_split = value.split(',')
if len(str_split) != 3:
raise ValueError
hs, ss, bs = value.split(',', 3)
h = float(hs)
s = float(ss)
b = float(bs)
if not ((0 <= h <= 360) and (0 <= s <= 100) and (0 <= b <= 100)):
raise ValueError
return h, s, b
validate(value)
classmethod
Value validation method.
Valid values are in format H,S,B. Value ranges: H(ue): 0-360 S(aturation): 0-100 B(rightness): 0-100
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: typing.Union[str, tuple[float, float, float]]) -> None:
"""Value validation method.
Valid values are in format H,S,B.
Value ranges:
H(ue): 0-360
S(aturation): 0-100
B(rightness): 0-100
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if isinstance(value, str):
str_value = str(value)
elif isinstance(value, tuple) and len(value) == 3:
str_value = f'{value[0]},{value[1]},{value[2]}'
else:
raise ValueError
ColorType.parse(str_value)
CommandType
Base command type class.
Source code in openhab/command_types.py
class CommandType(metaclass=abc.ABCMeta):
"""Base command type class."""
TYPENAME = ''
SUPPORTED_TYPENAMES: list[str] = []
UNDEF = 'UNDEF'
NULL = 'NULL'
UNDEFINED_STATES = [UNDEF, NULL]
@classmethod
def is_undefined(cls, value: typing.Any) -> bool:
"""Return true if given value is an undefined value in openHAB (i.e. UNDEF/NULL)."""
return value in CommandType.UNDEFINED_STATES
@classmethod
def get_type_for(
cls,
typename: str,
parent_cls: typing.Optional[type['CommandType']] = None,
) -> typing.Union[type['CommandType'], None]:
"""Get a class type for a given typename."""
if parent_cls is None:
parent_cls = CommandType
for a_type in parent_cls.__subclasses__():
if typename in a_type.SUPPORTED_TYPENAMES:
return a_type
# maybe a subclass of a subclass
result = a_type.get_type_for(typename, a_type)
if result is not None:
return result
return None
@classmethod
@abc.abstractmethod
def parse(cls, value: str) -> typing.Optional[typing.Any]:
"""Parse a given value."""
raise NotImplementedError
@classmethod
@abc.abstractmethod
def validate(cls, value: typing.Any) -> None:
"""Value validation method.
As this is the base class which should not be used
directly, we throw a NotImplementedError exception.
Args:
value (Object): The value to validate. The data_type of the value depends on the item
data_type and is checked accordingly.
Raises:
NotImplementedError: Raises NotImplementedError as the base class should never
be used directly.
"""
raise NotImplementedError
get_type_for(typename, parent_cls=None)
classmethod
Get a class type for a given typename.
Source code in openhab/command_types.py
@classmethod
def get_type_for(
cls,
typename: str,
parent_cls: typing.Optional[type['CommandType']] = None,
) -> typing.Union[type['CommandType'], None]:
"""Get a class type for a given typename."""
if parent_cls is None:
parent_cls = CommandType
for a_type in parent_cls.__subclasses__():
if typename in a_type.SUPPORTED_TYPENAMES:
return a_type
# maybe a subclass of a subclass
result = a_type.get_type_for(typename, a_type)
if result is not None:
return result
return None
is_undefined(value)
classmethod
Return true if given value is an undefined value in openHAB (i.e. UNDEF/NULL).
Source code in openhab/command_types.py
@classmethod
def is_undefined(cls, value: typing.Any) -> bool:
"""Return true if given value is an undefined value in openHAB (i.e. UNDEF/NULL)."""
return value in CommandType.UNDEFINED_STATES
parse(value)
abstractmethod
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
@abc.abstractmethod
def parse(cls, value: str) -> typing.Optional[typing.Any]:
"""Parse a given value."""
raise NotImplementedError
validate(value)
abstractmethod
classmethod
Value validation method.
As this is the base class which should not be used directly, we throw a NotImplementedError exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Object
|
The value to validate. The data_type of the value depends on the item data_type and is checked accordingly. |
required |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raises NotImplementedError as the base class should never be used directly. |
Source code in openhab/command_types.py
@classmethod
@abc.abstractmethod
def validate(cls, value: typing.Any) -> None:
"""Value validation method.
As this is the base class which should not be used
directly, we throw a NotImplementedError exception.
Args:
value (Object): The value to validate. The data_type of the value depends on the item
data_type and is checked accordingly.
Raises:
NotImplementedError: Raises NotImplementedError as the base class should never
be used directly.
"""
raise NotImplementedError
DateTimeType
Bases: CommandType
DateTimeType data_type class.
Source code in openhab/command_types.py
class DateTimeType(CommandType):
"""DateTimeType data_type class."""
TYPENAME = 'DateTime'
SUPPORTED_TYPENAMES = [TYPENAME]
@classmethod
def parse(cls, value: str) -> typing.Optional[datetime.datetime]:
"""Parse a given value."""
if value in DateTimeType.UNDEFINED_STATES:
return None
return dateutil.parser.parse(value)
@classmethod
def validate(cls, value: datetime.datetime) -> None:
"""Value validation method.
Valid values are any of data_type ``datetime.datetime``.
Args:
value (datetime.datetime): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if not isinstance(value, datetime.datetime):
raise ValueError
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[datetime.datetime]:
"""Parse a given value."""
if value in DateTimeType.UNDEFINED_STATES:
return None
return dateutil.parser.parse(value)
validate(value)
classmethod
Value validation method.
Valid values are any of data_type datetime.datetime.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
datetime
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: datetime.datetime) -> None:
"""Value validation method.
Valid values are any of data_type ``datetime.datetime``.
Args:
value (datetime.datetime): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if not isinstance(value, datetime.datetime):
raise ValueError
DecimalType
Bases: CommandType
DecimalType data_type class.
Source code in openhab/command_types.py
class DecimalType(CommandType):
"""DecimalType data_type class."""
TYPENAME = 'Decimal'
SUPPORTED_TYPENAMES = [TYPENAME, 'Quantity']
@classmethod
def parse(cls, value: str) -> typing.Union[None, tuple[typing.Union[int, float], str]]:
"""Parse a given value."""
if value in DecimalType.UNDEFINED_STATES:
return None
m = re.match(r'(-?[0-9.]+(?:[eE]-?[0-9]+)?)\s?(.*)?$', value)
if m:
value_value = m.group(1)
value_unit_of_measure = m.group(2)
try:
if '.' in value:
return_value: typing.Union[int, float] = float(value_value)
else:
return_value = int(value_value)
except ArithmeticError as exc:
raise ValueError(exc) from exc
return return_value, value_unit_of_measure
raise ValueError
@classmethod
def validate(cls, value: typing.Union[float, tuple[float, str], str]) -> None:
"""Value validation method.
Valid values are any of data_type:
- ``int``
- ``float``
- a tuple of (``int`` or ``float``, ``str``) for numeric value, unit of measure
- a ``str`` that can be parsed to one of the above by ``DecimalType.parse``
Args:
value (int, float, tuple, str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if isinstance(value, str):
DecimalType.parse(value)
elif isinstance(value, tuple) and len(value) == 2:
DecimalType.parse(f'{value[0]} {value[1]}')
elif not isinstance(value, (int, float)):
raise ValueError
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Union[None, tuple[typing.Union[int, float], str]]:
"""Parse a given value."""
if value in DecimalType.UNDEFINED_STATES:
return None
m = re.match(r'(-?[0-9.]+(?:[eE]-?[0-9]+)?)\s?(.*)?$', value)
if m:
value_value = m.group(1)
value_unit_of_measure = m.group(2)
try:
if '.' in value:
return_value: typing.Union[int, float] = float(value_value)
else:
return_value = int(value_value)
except ArithmeticError as exc:
raise ValueError(exc) from exc
return return_value, value_unit_of_measure
raise ValueError
validate(value)
classmethod
Value validation method.
Valid values are any of data_type
intfloat- a tuple of (
intorfloat,str) for numeric value, unit of measure - a
strthat can be parsed to one of the above byDecimalType.parse
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
(int, float, tuple, str)
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: typing.Union[float, tuple[float, str], str]) -> None:
"""Value validation method.
Valid values are any of data_type:
- ``int``
- ``float``
- a tuple of (``int`` or ``float``, ``str``) for numeric value, unit of measure
- a ``str`` that can be parsed to one of the above by ``DecimalType.parse``
Args:
value (int, float, tuple, str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if isinstance(value, str):
DecimalType.parse(value)
elif isinstance(value, tuple) and len(value) == 2:
DecimalType.parse(f'{value[0]} {value[1]}')
elif not isinstance(value, (int, float)):
raise ValueError
GroupType
Bases: CommandType
Group type.
Source code in openhab/command_types.py
class GroupType(CommandType):
"""Group type."""
TYPENAME = 'Group'
SUPPORTED_TYPENAMES = [TYPENAME]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in GroupType.UNDEFINED_STATES:
return None
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method."""
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in GroupType.UNDEFINED_STATES:
return None
return value
validate(value)
classmethod
Value validation method.
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method."""
IncreaseDecreaseType
Bases: StringType
IncreaseDecreaseType data_type class.
Source code in openhab/command_types.py
class IncreaseDecreaseType(StringType):
"""IncreaseDecreaseType data_type class."""
TYPENAME = 'IncreaseDecrease'
SUPPORTED_TYPENAMES = [TYPENAME]
INCREASE = 'INCREASE'
DECREASE = 'DECREASE'
POSSIBLE_VALUES = [INCREASE, DECREASE]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in IncreaseDecreaseType.UNDEFINED_STATES:
return None
if value not in IncreaseDecreaseType.POSSIBLE_VALUES:
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``INCREASE`` and ``DECREASE``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
IncreaseDecreaseType.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in IncreaseDecreaseType.UNDEFINED_STATES:
return None
if value not in IncreaseDecreaseType.POSSIBLE_VALUES:
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are INCREASE and DECREASE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``INCREASE`` and ``DECREASE``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
IncreaseDecreaseType.parse(value)
NextPrevious
Bases: StringType
NextPrevious data_type class.
Source code in openhab/command_types.py
class NextPrevious(StringType):
"""NextPrevious data_type class."""
TYPENAME = 'NextPrevious'
SUPPORTED_TYPENAMES = [TYPENAME]
NEXT = 'NEXT'
PREVIOUS = 'PREVIOUS'
POSSIBLE_VALUES = [NEXT, PREVIOUS]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in NextPrevious.UNDEFINED_STATES:
return None
if value not in NextPrevious.POSSIBLE_VALUES:
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``PLAY``, ``PAUSE``
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
NextPrevious.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in NextPrevious.UNDEFINED_STATES:
return None
if value not in NextPrevious.POSSIBLE_VALUES:
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are PLAY, PAUSE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``PLAY``, ``PAUSE``
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
NextPrevious.parse(value)
OnOffType
Bases: StringType
OnOffType data_type class.
Source code in openhab/command_types.py
class OnOffType(StringType):
"""OnOffType data_type class."""
TYPENAME = 'OnOff'
SUPPORTED_TYPENAMES = [TYPENAME]
ON = 'ON'
OFF = 'OFF'
POSSIBLE_VALUES = [ON, OFF]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in OnOffType.UNDEFINED_STATES:
return None
if value not in OnOffType.POSSIBLE_VALUES:
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``ON`` and ``OFF``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
OnOffType.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in OnOffType.UNDEFINED_STATES:
return None
if value not in OnOffType.POSSIBLE_VALUES:
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are ON and OFF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``ON`` and ``OFF``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
OnOffType.parse(value)
OpenCloseType
Bases: StringType
OpenCloseType data_type class.
Source code in openhab/command_types.py
class OpenCloseType(StringType):
"""OpenCloseType data_type class."""
TYPENAME = 'OpenClosed'
SUPPORTED_TYPENAMES = [TYPENAME]
OPEN = 'OPEN'
CLOSED = 'CLOSED'
POSSIBLE_VALUES = [OPEN, CLOSED]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in OpenCloseType.UNDEFINED_STATES:
return None
if value not in OpenCloseType.POSSIBLE_VALUES:
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``OPEN`` and ``CLOSED``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
OpenCloseType.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in OpenCloseType.UNDEFINED_STATES:
return None
if value not in OpenCloseType.POSSIBLE_VALUES:
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are OPEN and CLOSED.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``OPEN`` and ``CLOSED``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
OpenCloseType.parse(value)
PercentType
Bases: CommandType
PercentType data_type class.
Source code in openhab/command_types.py
class PercentType(CommandType):
"""PercentType data_type class."""
TYPENAME = 'Percent'
SUPPORTED_TYPENAMES = [TYPENAME]
@classmethod
def parse(cls, value: str) -> typing.Optional[float]:
"""Parse a given value."""
if value in PercentType.UNDEFINED_STATES:
return None
try:
f = float(value)
if not 0 <= f <= 100:
raise ValueError
return f
except Exception as e:
raise ValueError(e) from e
@classmethod
def validate(cls, value: float) -> None:
"""Value validation method.
Valid values are any of data_type ``float`` or ``int`` and must be greater of equal to 0
and smaller or equal to 100.
Args:
value (float): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if not (isinstance(value, (float, int)) and 0 <= value <= 100):
raise ValueError
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[float]:
"""Parse a given value."""
if value in PercentType.UNDEFINED_STATES:
return None
try:
f = float(value)
if not 0 <= f <= 100:
raise ValueError
return f
except Exception as e:
raise ValueError(e) from e
validate(value)
classmethod
Value validation method.
Valid values are any of data_type float or int and must be greater of equal to 0
and smaller or equal to 100.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: float) -> None:
"""Value validation method.
Valid values are any of data_type ``float`` or ``int`` and must be greater of equal to 0
and smaller or equal to 100.
Args:
value (float): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if not (isinstance(value, (float, int)) and 0 <= value <= 100):
raise ValueError
PlayPauseType
Bases: StringType
PlayPauseType data_type class.
Source code in openhab/command_types.py
class PlayPauseType(StringType):
"""PlayPauseType data_type class."""
TYPENAME = 'PlayPause'
SUPPORTED_TYPENAMES = [TYPENAME]
PLAY = 'PLAY'
PAUSE = 'PAUSE'
POSSIBLE_VALUES = [PLAY, PAUSE]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in PlayPauseType.UNDEFINED_STATES:
return None
if value not in PlayPauseType.POSSIBLE_VALUES:
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``PLAY``, ``PAUSE``
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
PlayPauseType.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in PlayPauseType.UNDEFINED_STATES:
return None
if value not in PlayPauseType.POSSIBLE_VALUES:
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are PLAY, PAUSE
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``PLAY``, ``PAUSE``
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
PlayPauseType.parse(value)
PointType
Bases: CommandType
PointType data_type class.
Source code in openhab/command_types.py
class PointType(CommandType):
"""PointType data_type class."""
TYPENAME = 'Point'
SUPPORTED_TYPENAMES = [TYPENAME]
@classmethod
def parse(cls, value: str) -> typing.Optional[tuple[float, float, float]]:
"""Parse a given value."""
if value in PercentType.UNDEFINED_STATES:
return None
value_split = value.split(',', maxsplit=2)
if not (1 < len(value_split) < 4):
raise ValueError
try:
latitude = float(value_split[0])
longitude = float(value_split[1])
altitude = 0.0
if len(value_split) == 3:
altitude = float(value_split[2])
except ArithmeticError as exc:
raise ValueError(exc) from exc
return latitude, longitude, altitude
@classmethod
def validate(cls, value: typing.Optional[typing.Union[str, tuple[typing.Union[float, int], typing.Union[float, int], typing.Union[float, int]]]]) -> None:
"""Value validation method.
A valid PointType is a tuple of three decimal values representing:
- latitude
- longitude
- altitude
Valid values are:
- a tuple of (``int`` or ``float``, ``int`` or ``float``, ``int`` or ``float``)
- a ``str`` that can be parsed to one of the above by ``DecimalType.parse``
Args:
value: The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if isinstance(value, str):
result = PointType.parse(value)
if result is None:
return
latitude, longitude, altitude = result
elif not (isinstance(value, tuple) and len(value) == 3):
raise ValueError
elif not (isinstance(value[0], (float, int)) and isinstance(value[1], (float, int)) and isinstance(value[2], (float, int))):
raise ValueError
else:
latitude, longitude, altitude = value
if not (-90 <= latitude <= 90):
msg = 'Latitude must be between -90 and 90, inclusive.'
raise ValueError(msg)
if not (-180 <= longitude <= 180):
msg = 'Longitude must be between -180 and 180, inclusive.'
raise ValueError(msg)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[tuple[float, float, float]]:
"""Parse a given value."""
if value in PercentType.UNDEFINED_STATES:
return None
value_split = value.split(',', maxsplit=2)
if not (1 < len(value_split) < 4):
raise ValueError
try:
latitude = float(value_split[0])
longitude = float(value_split[1])
altitude = 0.0
if len(value_split) == 3:
altitude = float(value_split[2])
except ArithmeticError as exc:
raise ValueError(exc) from exc
return latitude, longitude, altitude
validate(value)
classmethod
Value validation method.
A valid PointType is a tuple of three decimal values representing
- latitude
- longitude
- altitude
Valid values are
- a tuple of (
intorfloat,intorfloat,intorfloat) - a
strthat can be parsed to one of the above byDecimalType.parse
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Optional[Union[str, tuple[Union[float, int], Union[float, int], Union[float, int]]]]
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: typing.Optional[typing.Union[str, tuple[typing.Union[float, int], typing.Union[float, int], typing.Union[float, int]]]]) -> None:
"""Value validation method.
A valid PointType is a tuple of three decimal values representing:
- latitude
- longitude
- altitude
Valid values are:
- a tuple of (``int`` or ``float``, ``int`` or ``float``, ``int`` or ``float``)
- a ``str`` that can be parsed to one of the above by ``DecimalType.parse``
Args:
value: The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
if isinstance(value, str):
result = PointType.parse(value)
if result is None:
return
latitude, longitude, altitude = result
elif not (isinstance(value, tuple) and len(value) == 3):
raise ValueError
elif not (isinstance(value[0], (float, int)) and isinstance(value[1], (float, int)) and isinstance(value[2], (float, int))):
raise ValueError
else:
latitude, longitude, altitude = value
if not (-90 <= latitude <= 90):
msg = 'Latitude must be between -90 and 90, inclusive.'
raise ValueError(msg)
if not (-180 <= longitude <= 180):
msg = 'Longitude must be between -180 and 180, inclusive.'
raise ValueError(msg)
RewindFastforward
Bases: StringType
RewindFastforward data_type class.
Source code in openhab/command_types.py
class RewindFastforward(StringType):
"""RewindFastforward data_type class."""
TYPENAME = 'RewindFastforward'
SUPPORTED_TYPENAMES = [TYPENAME]
REWIND = 'REWIND'
FASTFORWARD = 'FASTFORWARD'
POSSIBLE_VALUES = [REWIND, FASTFORWARD]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in RewindFastforward.UNDEFINED_STATES:
return None
if value not in RewindFastforward.POSSIBLE_VALUES:
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``REWIND``, ``FASTFORWARD``
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
RewindFastforward.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in RewindFastforward.UNDEFINED_STATES:
return None
if value not in RewindFastforward.POSSIBLE_VALUES:
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are REWIND, FASTFORWARD
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``REWIND``, ``FASTFORWARD``
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
RewindFastforward.parse(value)
StopMoveType
Bases: StringType
UpDownType data_type class.
Source code in openhab/command_types.py
class StopMoveType(StringType):
"""UpDownType data_type class."""
TYPENAME = 'StopMove'
SUPPORTED_TYPENAMES = [TYPENAME]
STOP = 'STOP'
POSSIBLE_VALUES = [STOP]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in StopMoveType.UNDEFINED_STATES:
return None
if value not in StopMoveType.POSSIBLE_VALUES:
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``UP`` and ``DOWN``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
StopMoveType.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in StopMoveType.UNDEFINED_STATES:
return None
if value not in StopMoveType.POSSIBLE_VALUES:
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are UP and DOWN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``UP`` and ``DOWN``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
StopMoveType.parse(value)
StringType
Bases: CommandType
StringType data_type class.
Source code in openhab/command_types.py
class StringType(CommandType):
"""StringType data_type class."""
TYPENAME = 'String'
SUPPORTED_TYPENAMES = [TYPENAME]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in StringType.UNDEFINED_STATES:
return None
if not isinstance(value, str):
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are any of data_type string.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
StringType.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in StringType.UNDEFINED_STATES:
return None
if not isinstance(value, str):
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are any of data_type string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are any of data_type string.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
StringType.parse(value)
UndefType
Bases: CommandType
Undefined type.
Source code in openhab/command_types.py
class UndefType(CommandType):
"""Undefined type."""
TYPENAME = 'UnDef'
SUPPORTED_TYPENAMES = [TYPENAME]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in UndefType.UNDEFINED_STATES:
return None
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method."""
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in UndefType.UNDEFINED_STATES:
return None
return value
validate(value)
classmethod
Value validation method.
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method."""
UpDownType
Bases: StringType
UpDownType data_type class.
Source code in openhab/command_types.py
class UpDownType(StringType):
"""UpDownType data_type class."""
TYPENAME = 'UpDown'
SUPPORTED_TYPENAMES = [TYPENAME]
UP = 'UP'
DOWN = 'DOWN'
POSSIBLE_VALUES = [UP, DOWN]
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in UpDownType.UNDEFINED_STATES:
return None
if value not in UpDownType.POSSIBLE_VALUES:
raise ValueError
return value
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``UP`` and ``DOWN``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
UpDownType.parse(value)
parse(value)
classmethod
Parse a given value.
Source code in openhab/command_types.py
@classmethod
def parse(cls, value: str) -> typing.Optional[str]:
"""Parse a given value."""
if value in UpDownType.UNDEFINED_STATES:
return None
if value not in UpDownType.POSSIBLE_VALUES:
raise ValueError
return value
validate(value)
classmethod
Value validation method.
Valid values are UP and DOWN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises ValueError if an invalid value has been specified. |
Source code in openhab/command_types.py
@classmethod
def validate(cls, value: str) -> None:
"""Value validation method.
Valid values are ``UP`` and ``DOWN``.
Args:
value (str): The value to validate.
Raises:
ValueError: Raises ValueError if an invalid value has been specified.
"""
super().validate(value)
UpDownType.parse(value)