Skip to content

Commit

Permalink
Removing duplicities
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Feb 1, 2022
1 parent d885e9d commit 8b80a3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 36 deletions.
2 changes: 1 addition & 1 deletion fastybird_fb_bus_connector/api/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def transform_for_device(device_state: ConnectionState) -> DeviceConnectionState
return DeviceConnectionState.RUNNING

if device_state == ConnectionState.STOPPED:
return DeviceConnectionState.STOPPED
return DeviceConnectionState.STOPPED_BY_OPERATOR

# Unsupported state
return DeviceConnectionState.UNKNOWN
Expand Down
47 changes: 12 additions & 35 deletions fastybird_fb_bus_connector/registry/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,10 +383,18 @@ def format(
@property
def data_type_size(self) -> int:
"""Record data type bytes size"""
if self.data_type in (DataType.UCHAR, DataType.CHAR):
if self.data_type in (
DataType.UCHAR,
DataType.CHAR,
DataType.BUTTON,
DataType.SWITCH,
):
return 1

if self.data_type in (DataType.USHORT, DataType.SHORT):
if self.data_type in (
DataType.USHORT,
DataType.SHORT,
):
return 2

if self.data_type in (
Expand Down Expand Up @@ -420,7 +428,7 @@ def queryable(self) -> bool:
@property
def actual_value(self) -> Union[str, int, float, bool, datetime, ButtonPayload, SwitchPayload, None]:
"""Register actual value"""
return normalize_value(data_type=self.data_type, value=self._actual_value)
return normalize_value(data_type=self.data_type, value=self._actual_value, value_format=self.format)

# -----------------------------------------------------------------------------

Expand All @@ -438,7 +446,7 @@ def actual_value(self, value: Union[str, int, float, bool, datetime, ButtonPaylo
@property
def expected_value(self) -> Union[str, int, float, bool, datetime, ButtonPayload, SwitchPayload, None]:
"""Register expected value"""
return normalize_value(data_type=self.data_type, value=self._expected_value)
return normalize_value(data_type=self.data_type, value=self._expected_value, value_format=self.format)

# -----------------------------------------------------------------------------

Expand Down Expand Up @@ -592,37 +600,6 @@ def name(self) -> Optional[str]:

# -----------------------------------------------------------------------------

@property
def actual_value(self) -> Union[str, int, float, bool, datetime, ButtonPayload, SwitchPayload, None]:
"""Register actual value"""
return normalize_value(data_type=self.data_type, value=self._actual_value, value_format=self.format)

# -----------------------------------------------------------------------------

@actual_value.setter
def actual_value(self, value: Union[str, int, float, bool, datetime, ButtonPayload, SwitchPayload]) -> None:
"""Set register actual value"""
self._actual_value = value

# -----------------------------------------------------------------------------

@property
def expected_value(self) -> Union[str, int, float, bool, datetime, ButtonPayload, SwitchPayload, None]:
"""Register expected value"""
return normalize_value(data_type=self.data_type, value=self._expected_value, value_format=self.format)

# -----------------------------------------------------------------------------

@expected_value.setter
def expected_value(
self,
value: Union[str, int, float, bool, datetime, ButtonPayload, SwitchPayload, None],
) -> None:
"""Set register expected value"""
self._expected_value = value

# -----------------------------------------------------------------------------

@property
def format(
self,
Expand Down

0 comments on commit 8b80a3b

Please sign in to comment.