Fixing up style errors in line with tox.

This commit is contained in:
sibowler
2021-12-14 06:16:31 +11:00
committed by rospogrigio
parent 61896605b8
commit a0fff6ee2f
3 changed files with 51 additions and 35 deletions

View File

@@ -46,7 +46,15 @@ DATA_DISCOVERY = "discovery"
DOMAIN = "localtuya"
# Platforms in this list must support config flows
PLATFORMS = ["binary_sensor", "cover", "fan", "light", "number",
"select", "sensor", "switch"]
PLATFORMS = [
"binary_sensor",
"cover",
"fan",
"light",
"number",
"select",
"sensor",
"switch",
]
TUYA_DEVICE = "tuya_device"

View File

@@ -24,10 +24,12 @@ def flow_schema(dps):
"""Return schema used in config flow."""
return {
vol.Optional(CONF_MIN_VALUE, default=DEFAULT_MIN): vol.All(
vol.Coerce(float), vol.Range(min=-1000000.0, max=1000000.0),
vol.Coerce(float),
vol.Range(min=-1000000.0, max=1000000.0),
),
vol.Required(CONF_MAX_VALUE, default=DEFAULT_MAX): vol.All(
vol.Coerce(float), vol.Range(min=-1000000.0, max=1000000.0),
vol.Coerce(float),
vol.Range(min=-1000000.0, max=1000000.0),
),
}
@@ -46,11 +48,11 @@ class LocaltuyaNumber(LocalTuyaEntity, NumberEntity):
super().__init__(device, config_entry, sensorid, _LOGGER, **kwargs)
self._state = STATE_UNKNOWN
self._minValue = DEFAULT_MIN
if (CONF_MIN_VALUE in self._config):
self._minValue = self._config.get(CONF_MIN_VALUE)
self._min_value = DEFAULT_MIN
if CONF_MIN_VALUE in self._config:
self._min_value = self._config.get(CONF_MIN_VALUE)
self._maxValue = self._config.get(CONF_MAX_VALUE)
self._max_value = self._config.get(CONF_MAX_VALUE)
@property
def value(self) -> float:
@@ -60,12 +62,12 @@ class LocaltuyaNumber(LocalTuyaEntity, NumberEntity):
@property
def min_value(self) -> float:
"""Return the minimum value."""
return self._minValue
return self._min_value
@property
def max_value(self) -> float:
"""Return the maximum value."""
return self._maxValue
return self._max_value
@property
def device_class(self):

View File

@@ -38,43 +38,49 @@ class LocaltuyaSelect(LocalTuyaEntity, SelectEntity):
"""Initialize the Tuya sensor."""
super().__init__(device, config_entry, sensorid, _LOGGER, **kwargs)
self._state = STATE_UNKNOWN
self._validOptions = self._config.get(CONF_OPTIONS).split(';')
self._state_friendly = ""
self._valid_options = self._config.get(CONF_OPTIONS).split(";")
# Set Display options
self._displayOptions = []
displayOptionsStr = ""
if (CONF_OPTIONS_FRIENDLY in self._config):
displayOptionsStr = self._config.get(CONF_OPTIONS_FRIENDLY).strip()
_LOGGER.debug("Display Options Configured: " + displayOptionsStr)
self._display_options = []
display_options_str = ""
if CONF_OPTIONS_FRIENDLY in self._config:
display_options_str = self._config.get(CONF_OPTIONS_FRIENDLY).strip()
_LOGGER.debug("Display Options Configured: %s", display_options_str)
if (displayOptionsStr.find(";") >= 0):
self._displayOptions = displayOptionsStr.split(';')
elif (len(displayOptionsStr.strip()) > 0):
self._displayOptions.append(displayOptionsStr)
if display_options_str.find(";") >= 0:
self._display_options = display_options_str.split(";")
elif len(display_options_str.strip()) > 0:
self._display_options.append(display_options_str)
else:
# Default display string to raw string
_LOGGER.debug("No Display options configured - defaulting to raw values")
self._displayOptions = self._validOptions
self._display_options = self._valid_options
_LOGGER.debug("Total Raw Options: " + str(len(self._validOptions)) +
" - Total Display Options: " + str(len(self._displayOptions)))
if (len(self._validOptions) > len(self._displayOptions)):
# If list of display items smaller than list of valid items,
_LOGGER.debug(
"Total Raw Options: %s - Total Display Options: %s",
str(len(self._valid_options)),
str(len(self._display_options))
)
if len(self._valid_options) > len(self._display_options):
# If list of display items smaller than list of valid items,
# then default remaining items to be the raw value
_LOGGER.debug("Valid options is larger than display options - \
filling up with raw values")
for i in range(len(self._displayOptions), len(self._validOptions)):
self._displayOptions.append(self._validOptions[i])
_LOGGER.debug(
"Valid options is larger than display options - \
filling up with raw values"
)
for i in range(len(self._display_options), len(self._valid_options)):
self._display_options.append(self._valid_options[i])
@property
def current_option(self) -> str:
"""Return the current value."""
return self._stateFriendly
return self._state_friendly
@property
def options(self) -> list:
"""Return the list of values."""
return self._displayOptions
return self._display_options
@property
def device_class(self):
@@ -83,14 +89,14 @@ class LocaltuyaSelect(LocalTuyaEntity, SelectEntity):
async def async_select_option(self, option: str) -> None:
"""Update the current value."""
optionValue = self._validOptions[self._displayOptions.index(option)]
_LOGGER.debug("Sending Option: " + option + " -> " + optionValue)
await self._device.set_dp(optionValue, self._dp_id)
option_value = self._valid_options[self._display_options.index(option)]
_LOGGER.debug("Sending Option: " + option + " -> " + option_value)
await self._device.set_dp(option_value, self._dp_id)
def status_updated(self):
"""Device status was updated."""
state = self.dps(self._dp_id)
self._stateFriendly = self._displayOptions[self._validOptions.index(state)]
self._state_friendly = self._display_options[self._valid_options.index(state)]
self._state = state