Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unsupported operand type(s) for /: 'NoneType' and 'int' #345

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Changes from 1 commit
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
15 changes: 11 additions & 4 deletions custom_components/localtuya/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@ def extra_state_attributes(self):
if self.has_config(CONF_CURRENT):
attrs[ATTR_CURRENT] = self.dp_value(self._config[CONF_CURRENT])
if self.has_config(CONF_CURRENT_CONSUMPTION):
attrs[ATTR_CURRENT_CONSUMPTION] = (
self.dp_value(self._config[CONF_CURRENT_CONSUMPTION]) / 10
)
value_cc = self.dp_value(self._config[CONF_CURRENT_CONSUMPTION])
if value_cc is not None:
attrs[ATTR_CURRENT_CONSUMPTION] = value_cc / 10
else:
attrs[ATTR_CURRENT_CONSUMPTION] = None

if self.has_config(CONF_VOLTAGE):
attrs[ATTR_VOLTAGE] = self.dp_value(self._config[CONF_VOLTAGE]) / 10
value_v = attrs[ATTR_VOLTAGE] = self.dp_value(self._config[CONF_VOLTAGE])
if value_v is not None:
attrs[ATTR_VOLTAGE] = value_v / 10
else:
attrs[ATTR_VOLTAGE] = None
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if self.has_config(CONF_CURRENT_CONSUMPTION):
attrs[ATTR_CURRENT_CONSUMPTION] = (
self.dp_value(self._config[CONF_CURRENT_CONSUMPTION]) / 10
)
value_cc = self.dp_value(self._config[CONF_CURRENT_CONSUMPTION])
if value_cc is not None:
attrs[ATTR_CURRENT_CONSUMPTION] = value_cc / 10
else:
attrs[ATTR_CURRENT_CONSUMPTION] = None
if self.has_config(CONF_VOLTAGE):
attrs[ATTR_VOLTAGE] = self.dp_value(self._config[CONF_VOLTAGE]) / 10
value_v = attrs[ATTR_VOLTAGE] = self.dp_value(self._config[CONF_VOLTAGE])
if value_v is not None:
attrs[ATTR_VOLTAGE] = value_v / 10
else:
attrs[ATTR_VOLTAGE] = None
if self.has_config(CONF_CURRENT_CONSUMPTION):
val_cc = self.dp_value(self._config[CONF_CURRENT_CONSUMPTION])
attrs[ATTR_CURRENT_CONSUMPTION] = None if val_cc is None else val_cc / 10
if self.has_config(CONF_VOLTAGE):
val_vol = self.dp_value(self._config[CONF_VOLTAGE])
attrs[ATTR_VOLTAGE] = None if val_vol is None else val_vol / 10

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code amended based on review.


# Store the state
if self._state is not None:
Expand Down
Loading