Fixing up style errors in line with tox.
This commit is contained in:
@@ -46,7 +46,15 @@ DATA_DISCOVERY = "discovery"
|
|||||||
DOMAIN = "localtuya"
|
DOMAIN = "localtuya"
|
||||||
|
|
||||||
# Platforms in this list must support config flows
|
# Platforms in this list must support config flows
|
||||||
PLATFORMS = ["binary_sensor", "cover", "fan", "light", "number",
|
PLATFORMS = [
|
||||||
"select", "sensor", "switch"]
|
"binary_sensor",
|
||||||
|
"cover",
|
||||||
|
"fan",
|
||||||
|
"light",
|
||||||
|
"number",
|
||||||
|
"select",
|
||||||
|
"sensor",
|
||||||
|
"switch",
|
||||||
|
]
|
||||||
|
|
||||||
TUYA_DEVICE = "tuya_device"
|
TUYA_DEVICE = "tuya_device"
|
||||||
|
@@ -24,10 +24,12 @@ def flow_schema(dps):
|
|||||||
"""Return schema used in config flow."""
|
"""Return schema used in config flow."""
|
||||||
return {
|
return {
|
||||||
vol.Optional(CONF_MIN_VALUE, default=DEFAULT_MIN): vol.All(
|
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.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)
|
super().__init__(device, config_entry, sensorid, _LOGGER, **kwargs)
|
||||||
self._state = STATE_UNKNOWN
|
self._state = STATE_UNKNOWN
|
||||||
|
|
||||||
self._minValue = DEFAULT_MIN
|
self._min_value = DEFAULT_MIN
|
||||||
if (CONF_MIN_VALUE in self._config):
|
if CONF_MIN_VALUE in self._config:
|
||||||
self._minValue = self._config.get(CONF_MIN_VALUE)
|
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
|
@property
|
||||||
def value(self) -> float:
|
def value(self) -> float:
|
||||||
@@ -60,12 +62,12 @@ class LocaltuyaNumber(LocalTuyaEntity, NumberEntity):
|
|||||||
@property
|
@property
|
||||||
def min_value(self) -> float:
|
def min_value(self) -> float:
|
||||||
"""Return the minimum value."""
|
"""Return the minimum value."""
|
||||||
return self._minValue
|
return self._min_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def max_value(self) -> float:
|
def max_value(self) -> float:
|
||||||
"""Return the maximum value."""
|
"""Return the maximum value."""
|
||||||
return self._maxValue
|
return self._max_value
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
|
@@ -38,43 +38,49 @@ class LocaltuyaSelect(LocalTuyaEntity, SelectEntity):
|
|||||||
"""Initialize the Tuya sensor."""
|
"""Initialize the Tuya sensor."""
|
||||||
super().__init__(device, config_entry, sensorid, _LOGGER, **kwargs)
|
super().__init__(device, config_entry, sensorid, _LOGGER, **kwargs)
|
||||||
self._state = STATE_UNKNOWN
|
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
|
# Set Display options
|
||||||
self._displayOptions = []
|
self._display_options = []
|
||||||
displayOptionsStr = ""
|
display_options_str = ""
|
||||||
if (CONF_OPTIONS_FRIENDLY in self._config):
|
if CONF_OPTIONS_FRIENDLY in self._config:
|
||||||
displayOptionsStr = self._config.get(CONF_OPTIONS_FRIENDLY).strip()
|
display_options_str = self._config.get(CONF_OPTIONS_FRIENDLY).strip()
|
||||||
_LOGGER.debug("Display Options Configured: " + displayOptionsStr)
|
_LOGGER.debug("Display Options Configured: %s", display_options_str)
|
||||||
|
|
||||||
if (displayOptionsStr.find(";") >= 0):
|
if display_options_str.find(";") >= 0:
|
||||||
self._displayOptions = displayOptionsStr.split(';')
|
self._display_options = display_options_str.split(";")
|
||||||
elif (len(displayOptionsStr.strip()) > 0):
|
elif len(display_options_str.strip()) > 0:
|
||||||
self._displayOptions.append(displayOptionsStr)
|
self._display_options.append(display_options_str)
|
||||||
else:
|
else:
|
||||||
# Default display string to raw string
|
# Default display string to raw string
|
||||||
_LOGGER.debug("No Display options configured - defaulting to raw values")
|
_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)) +
|
_LOGGER.debug(
|
||||||
" - Total Display Options: " + str(len(self._displayOptions)))
|
"Total Raw Options: %s - Total Display Options: %s",
|
||||||
if (len(self._validOptions) > len(self._displayOptions)):
|
str(len(self._valid_options)),
|
||||||
# If list of display items smaller than list of valid items,
|
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
|
# then default remaining items to be the raw value
|
||||||
_LOGGER.debug("Valid options is larger than display options - \
|
_LOGGER.debug(
|
||||||
filling up with raw values")
|
"Valid options is larger than display options - \
|
||||||
for i in range(len(self._displayOptions), len(self._validOptions)):
|
filling up with raw values"
|
||||||
self._displayOptions.append(self._validOptions[i])
|
)
|
||||||
|
for i in range(len(self._display_options), len(self._valid_options)):
|
||||||
|
self._display_options.append(self._valid_options[i])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current_option(self) -> str:
|
def current_option(self) -> str:
|
||||||
"""Return the current value."""
|
"""Return the current value."""
|
||||||
return self._stateFriendly
|
return self._state_friendly
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def options(self) -> list:
|
def options(self) -> list:
|
||||||
"""Return the list of values."""
|
"""Return the list of values."""
|
||||||
return self._displayOptions
|
return self._display_options
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
@@ -83,14 +89,14 @@ class LocaltuyaSelect(LocalTuyaEntity, SelectEntity):
|
|||||||
|
|
||||||
async def async_select_option(self, option: str) -> None:
|
async def async_select_option(self, option: str) -> None:
|
||||||
"""Update the current value."""
|
"""Update the current value."""
|
||||||
optionValue = self._validOptions[self._displayOptions.index(option)]
|
option_value = self._valid_options[self._display_options.index(option)]
|
||||||
_LOGGER.debug("Sending Option: " + option + " -> " + optionValue)
|
_LOGGER.debug("Sending Option: " + option + " -> " + option_value)
|
||||||
await self._device.set_dp(optionValue, self._dp_id)
|
await self._device.set_dp(option_value, self._dp_id)
|
||||||
|
|
||||||
def status_updated(self):
|
def status_updated(self):
|
||||||
"""Device status was updated."""
|
"""Device status was updated."""
|
||||||
state = self.dps(self._dp_id)
|
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
|
self._state = state
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user