Skip to content

Commit

Permalink
init codespell
Browse files Browse the repository at this point in the history
  • Loading branch information
xZetsubou committed Jan 25, 2025
1 parent 48d206b commit 7c27a79
Show file tree
Hide file tree
Showing 21 changed files with 101 additions and 41 deletions.
63 changes: 59 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,68 @@ on:
pull_request:
workflow_dispatch:

env:
PY_VERSION: "3.13"

jobs:
black:
runs-on: "ubuntu-latest"
base:
name: Prepare dependences
runs-on: ubuntu-latest
outputs:
PY_PATH: ${{ steps.install_depends.outputs.PY_PATH }}
steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: "Setup Python"
uses: actions/setup-python@v5
with:
python-version: ${{env.PY_VERSION}}

- name: "Install dependencies"
run: pip3 install -r requirements_test.txt
id: install_depends
run: |
echo "PY_PATH=${{env.pythonLocation}}" >> $GITHUB_OUTPUT
pip install -r requirements_test.txt
- name: "Cache dependencies"
uses: actions/[email protected]
with:
path: ${{env.pythonLocation}}
key: ${{ runner.os }}-pip-dependencies-${{ hashFiles('requirements.txt') }}

black:
name: Black codestyle
runs-on: ubuntu-latest
needs: base
steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: Restore Python
uses: actions/cache/[email protected]
with:
path: ${{needs.base.outputs.PY_PATH}}
fail-on-cache-miss: true
key: ${{ runner.os }}-pip-dependencies-${{ hashFiles('requirements.txt') }}

- name: "Black codestyle check"
run: black --check --diff .
run: ${{needs.base.outputs.PY_PATH}}/bin/black --check --diff .

codespell:
name: "Codespell check"
runs-on: ubuntu-latest
needs: base
steps:
- name: "Checkout"
uses: actions/checkout@v4

- name: Restore Python
uses: actions/cache/[email protected]
with:
path: ${{needs.base.outputs.PY_PATH}}
fail-on-cache-miss: true
key: ${{ runner.os }}-pip-dependencies-${{ hashFiles('requirements.txt') }}

- name: "Codespell check"
run: ${{needs.base.outputs.PY_PATH}}/bin/codespell
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The Cloud API account configuration is not mandatory (LocalTuya can work also wi

sean6541, for the working (standard) Python Handler for Tuya devices.

[jasonacox](https://github.com/jasonacox), for the TinyTuya project from where I big help and refrences to upgrade integration.
[jasonacox](https://github.com/jasonacox), for the TinyTuya project from where I big help and references to upgrade integration.

[uzlonewolf](https://github.com/uzlonewolf), for maintaining in TinyTuya who improved the tool so much and introduce new features like new protocols etc..

Expand Down
8 changes: 4 additions & 4 deletions custom_components/localtuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry):
new_version = ENTRIES_VERSION
stored_entries = hass.config_entries.async_entries(DOMAIN)
if config_entry.version == 1:
# This an old version of original integration no nned to put it here.
# This an old version of original integration no need to put it here.
pass
# Update to version 3
if config_entry.version == 2:
Expand Down Expand Up @@ -530,9 +530,9 @@ def check_if_device_disabled(hass: HomeAssistant, entry: ConfigEntry, dev_id: st
entries = er.async_entries_for_config_entry(ent_reg, entry.entry_id)
ha_device_id: str = None

for entitiy in entries:
if dev_id in entitiy.unique_id:
ha_device_id = entitiy.device_id
for entity in entries:
if dev_id in entity.unique_id:
ha_device_id = entity.device_id
break

if ha_device_id and (device := dr.async_get(hass).async_get(ha_device_id)):
Expand Down
6 changes: 3 additions & 3 deletions custom_components/localtuya/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def flow_schema(dps):
}


# Convertors
# Converters
def f_to_c(num):
return (num - 32) * 5 / 9 if num else num

Expand Down Expand Up @@ -243,7 +243,7 @@ def __init__(
self._min_temp = self._config.get(CONF_MIN_TEMP, DEFAULT_MIN_TEMP)
self._max_temp = self._config.get(CONF_MAX_TEMP, DEFAULT_MAX_TEMP)

# Temperture unit
# Temperature unit
config_temp_unit = self._config.get(CONF_TEMPERATURE_UNIT, "")
target_unit, *current_unit = config_temp_unit.split("/")
set_temp_unit = UnitOfTemperature.CELSIUS
Expand Down Expand Up @@ -418,7 +418,7 @@ async def async_set_temperature(self, **kwargs):
temperature = kwargs[ATTR_TEMPERATURE]

if self._target_temp_forced_to_celsius:
# Revert temperture to Fahrenheit it was forced to celsius
# Revert temperature to Fahrenheit it was forced to celsius
temperature = round(c_to_f(temperature))

temperature = round(temperature / self._precision_target)
Expand Down
10 changes: 5 additions & 5 deletions custom_components/localtuya/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ async def async_step_add_device(self, user_input=None):
for fail_dev in fails.values():
devices_fails += f"\n{fail_dev['name']}: {fail_dev['reason']}"

msg = f"Sucessed devices: ``{len(devices)}``\n ```{devices_sucessed}\n```"
msg = f"Succeeded devices: ``{len(devices)}``\n ```{devices_sucessed}\n```"
if fails:
msg += f" \n Failed devices: ``{len(fails)}``\n ```{devices_fails}\n```"

Expand Down Expand Up @@ -611,7 +611,7 @@ async def async_step_auto_configure_device(self, user_input=None):
errors = {}
placeholders = {}

# Gather the informations
# Gather the information
is_cloud = not self.config_entry.data.get(CONF_NO_CLOUD)
dev_id = self.selected_device
category = None
Expand Down Expand Up @@ -751,7 +751,7 @@ async def async_step_configure_entity(self, user_input=None):
dev_id = self.device_data[CONF_DEVICE_ID]
new_data = self.config_entry.data.copy()
entry_id = self.config_entry.entry_id
# Removing the unwanted entites.
# Removing the unwanted entities.
entitesNames = [
name.get(CONF_FRIENDLY_NAME)
for name in self.device_data[CONF_ENTITIES]
Expand Down Expand Up @@ -1280,7 +1280,7 @@ async def validate_input(hass: HomeAssistant, entry_id, data):
detected_dps = {}

# if manual DPs are set, merge these.
# detected_dps_device used to pervent user from bypass handshake manual dps.
# detected_dps_device used to prevent user from bypass handshake manual dps.
detected_dps_device = detected_dps.copy()
logger.debug("Detected DPS: %s", detected_dps)
if CONF_MANUAL_DPS in data:
Expand Down Expand Up @@ -1316,7 +1316,7 @@ async def validate_input(hass: HomeAssistant, entry_id, data):
# won't work in this case
if not bypass_connection and error:
raise error
# If bypass handshake. otherwise raise faild to make handshake with device.
# If bypass handshake. otherwise raise failed to make handshake with device.
# --- Cloud: We will use the DPS found on cloud if exists.
# --- No cloud: user will have to input the DPS manually.
if not detected_dps_device and not (
Expand Down
2 changes: 1 addition & 1 deletion custom_components/localtuya/core/ha_entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def gen_localtuya_entities(localtuya_data: dict, tuya_category: str) -> list[dic
entities[entity.get(CONF_ID)] = entity
_LOGGER.debug(f"{device_name}: Entity configured: {entity}")

# sort entites by id
# sort entities by id
sorted_ids = sorted(entities, key=int)

# convert to list of configs
Expand Down
6 changes: 3 additions & 3 deletions custom_components/localtuya/core/ha_entities/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CLOUD_VALUE:
`value_key(str)`: The "key" name of the targeted value.\n
`prefer_type`: Convert values
Integer: Type(value) ( int, float or str ).\n
Enums: convert the values to [dict or str splitted by comma, default is list].\n
Enums: convert the values to [dict or str split by comma, default is list].\n
`remap_values(dict)`: Used to remap dict values, if prefer_type is dict.\n
`reverse_dict(bool)`: Reverse dict keys, value, if prefer_type is dict.\n
`scale(bool)`: For integers, scale final value.\n
Expand Down Expand Up @@ -122,7 +122,7 @@ class DPCode(StrEnum):
ALARM_TIME = "alarm_time" # Alarm time
ALARM_VOLUME = "alarm_volume" # Alarm volume
ALL_ENERGY = "all_energy"
AMBIEN = "ambien"
AMBIEN = "ambien" # codespell:ignore
ANGLE_HORIZONTAL = "angle_horizontal"
ANGLE_VERTICAL = "angle_vertical"
ANION = "anion" # Ionizer unit
Expand Down Expand Up @@ -303,7 +303,7 @@ class DPCode(StrEnum):
ENERGY_REVERSE_B = "energy_reverse_b"
ENERGY_REVERSE_C = "energy_reverse_c"
EQUIPMENT_TIME = "equipment_time"
ERRO = "erro"
ERRO = "erro" # codespell:ignore
FAN_BEEP = "fan_beep" # Sound
FAN_COOL = "fan_cool" # Cool wind
FAN_COUNTDOWN = "fan_countdown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def localtuya_binarySensor(state_on="1"):
# https://developer.tuya.com/en/docs/iot/categoryfs?id=Kaiuz1xweel1c
"fs": (
LocalTuyaEntity(
id=DPCode.ERRO,
id=DPCode.ERRO, # codespell:ignore
name="Error",
device_class=BinarySensorDeviceClass.PROBLEM,
entity_category=EntityCategory.DIAGNOSTIC,
Expand Down
6 changes: 3 additions & 3 deletions custom_components/localtuya/core/ha_entities/selects.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def localtuya_selector(options):
),
LocalTuyaEntity(
id=DPCode.EARTH_TEST,
name="Earch Test",
name="Earth Test",
entity_category=EntityCategory.CONFIG,
custom_configs=localtuya_selector(
{"enabled_energy": "Enable", "forbidden_energy": "Disable"}
Expand Down Expand Up @@ -580,7 +580,7 @@ def localtuya_selector(options):
entity_category=EntityCategory.CONFIG,
name="Record Mode",
custom_configs=localtuya_selector(
{"1": "Record Events Only", "2": "Allways Record"}
{"1": "Record Events Only", "2": "Always Record"}
),
),
LocalTuyaEntity(
Expand Down Expand Up @@ -759,7 +759,7 @@ def localtuya_selector(options):
name="Direction",
custom_configs=localtuya_selector(
{
"foward": "Forward",
"forward": "Forward",
"backward": "Backward",
"turn_left": "Left",
"turn_right": "Right",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/localtuya/core/ha_entities/switches.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@
"fskg": (
LocalTuyaEntity(
id=DPCode.BACKLIGHT_SWITCH,
name="LED Siwtch",
name="LED Switch",
icon="mdi:led-outline",
entity_category=EntityCategory.CONFIG,
),
Expand Down
4 changes: 2 additions & 2 deletions custom_components/localtuya/core/pytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def debug(self, msg, *args, force=False):
return self._logger.log(logging.DEBUG, msg, *args)

def info(self, msg, *args, clear_warning=False):
"""Info level log. clear_warning to re-enable warings msgs if duplicated"""
"""Info level log. clear_warning to re-enable warnings msgs if duplicated"""
if clear_warning:
self._last_warning = ""

Expand Down Expand Up @@ -1296,7 +1296,7 @@ def _decode_payload(self, payload):
self.debug("payload was not string type and decoding failed")
return self.error_json(ERR_JSON, payload)

if "data unvalid" in payload:
if "data unvalid" in payload: # codespell:ignore
if self.version <= 3.3:
self.dev_type = "type_0d"
self.debug(
Expand Down
2 changes: 1 addition & 1 deletion custom_components/localtuya/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def _current_state(self) -> str:
self._current_state_action = STATE_STOPPED
if state in (STATE_SET_CLOSING, STATE_SET_OPENING):
set_pos = self._set_new_position
# Reset state whenn cover reached the position.
# Reset state when cover reached the position.
if curr_pos - set_pos < 5 and curr_pos - set_pos >= -5:
self._current_state_action = STATE_STOPPED

Expand Down
4 changes: 2 additions & 2 deletions custom_components/localtuya/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"Night": "bd76000168ffff",
"Read": "fffcf70168ffff",
"Meeting": "cf38000168ffff",
"Leasure": "3855b40168ffff",
"Leisure": "3855b40168ffff",
"Scenario 1": "scene_1",
"Scenario 2": "scene_2",
"Scenario 3": "scene_3",
Expand All @@ -77,7 +77,7 @@
"Read 2": "010e0d000084000003e800000000",
"Meeting": "020e0d0000000000000003e803e8",
"Working": "020e0d00001403e803e800000000",
"Leasure 1": "030e0d0000000000000001f401f4",
"Leisure 1": "030e0d0000000000000001f401f4",
"Leisure 2": "030e0d0000e80383031c00000000",
"Soft": "04464602007803e803e800000000464602007803e8000a00000000",
"Rainbow": "05464601000003e803e800000000464601007803e803e80000000046460100f003e803"
Expand Down
3 changes: 1 addition & 2 deletions custom_components/localtuya/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ async def async_learn_command(self, **kwargs: Any) -> None:
raise ServiceValidationError(f"Remote {self.entity_id} is turned off")

now, timeout = 0, kwargs.get(ATTR_TIMEOUT, 30)
sucess = False

device = kwargs.get(ATTR_DEVICE)
commands = kwargs.get(ATTR_COMMAND)
Expand Down Expand Up @@ -238,7 +237,7 @@ async def async_learn_command(self, **kwargs: Any) -> None:
self.hass, notification_id="learn_command"
)

# code retrive sucess and it's sotred in self._last_code
# code retrieve success and it's stored in self._last_code
# we will store the codes.

if command != commands[-1]:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/localtuya/templates/sample_2g_switch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# - 1st is write the yaml ur self:
# --[ Keep in mind there is no valid check atm ]

# - 2st is to export ur device file from config flow. [ Recommended ]:
# - 2nd is to export ur device file from config flow. [ Recommended ]:
# -- in HA Dashboard go to [ Devices -> localtuya -> Configure -> Edit Device * choose the device u want to export
# --- Export the device config then submit]

Expand All @@ -37,7 +37,7 @@

# How to import:
# -- When u add new device when the form [ Pick Entity type selection ]
# --- Import template Form will show up showing avaliable templates in templates folder.
# --- Import template Form will show up showing available templates in templates folder.

# -- templates in [custom_components/localtuya/templates]
# -- Templates files will load up with HA so adding files will require restarting HA to show up.
2 changes: 1 addition & 1 deletion documentation/docs/auto_configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ By known the `category` we use that to get all the possible entities from stored
_Now that we know the device `category` and `Codes` we can start add the entities._

In `/localtuya/core/ha_entities` open the file named with `entity type` you want to add.<br>
All files contains `constant dict` (1) includes all known `categories` and possible entites.<br>
All files contains `constant dict` (1) includes all known `categories` and possible entities.<br>
{.annotate}

1. e.g `COVERS or SWITCHES`
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
!!! abstract ""
A device that has [Low Power Mode](https://developer.tuya.com/en/docs/iot-device-dev/Low_consumption_Wi_Fi?id=Kay3gha1um42e){target="_blank"}, applied on such as __`Wi-Fi door locks and sensors`__. <br>
The device will report its status every x minutes. Most of the time, the device will go into sleep mode, and most likely it will disconnect from the network.
Some Device has an option to control the reports peroid.
Some Device has an option to control the reports period.
In order to add this device, you need to specify the device sleep time in the [device configartion](../usage/configure_add_device). <br>
!!! tip ""
If you add the device while it's sleeping and it's `disconnected` from the network, it won't connect <br>
Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/ha_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ that can be used on automation or monitoring your device behaviour from [Develop
| `localtuya_device_dp_triggered` | `#!json {"data": {"device_id", "dp", "value"} }`
| `localtuya_states_update` | `#!json {"data": {"device_id", "old_states", "new_states"} }`

Exaples
Examples
=== "localtuya_device_triggered"

```yaml
Expand Down
2 changes: 1 addition & 1 deletion pylint.rc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ confidence=
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once). You can also use "--disable=all" to
# disable everything first and then reenable specific checks. For example, if
# disable everything first and then re-enable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
target-version = ["py312"]
include = 'custom_components/localtuya/.*\.py'

[tool.codespell]
skip = '*.pyc,*.pyi,*~,*.json'
ignore-words-list = "hass,contiuation"
count = true
quiet-level = 3

# pylint config stolen from Home Assistant
[tool.pylint.MAIN]
# Use a conservative default here; 2 should speed up most setups and not hurt
Expand Down
4 changes: 2 additions & 2 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
black==24.8.0
codespell==2.0.0
codespell==2.3.0
flake8==3.9.2
mypy==0.901
pydocstyle==6.1.1
pylint==2.8.2
pylint-strict-informational==0.1
homeassistant==2024.11.0
homeassistant==2025.1.0

0 comments on commit 7c27a79

Please sign in to comment.