Skip to content

Commit

Permalink
Merge pull request #1 from cdnninja/corrections
Browse files Browse the repository at this point in the history
fix: add translation file
  • Loading branch information
cdnninja authored Apr 14, 2024
2 parents e26ed0c + e18fbb7 commit df44835
Show file tree
Hide file tree
Showing 11 changed files with 163 additions and 91 deletions.
118 changes: 59 additions & 59 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
---
ci:
autoupdate_commit_msg: "chore: pre-commit autoupdate"
autoupdate_commit_msg: "chore: pre-commit autoupdate"
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args:
- --ignore-words-list=fro,hass
- --skip="./.*,*.csv,*.json,*.ambr"
- --quiet-level=2
exclude_types: [csv, json]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
exclude: (.vscode|.devcontainer)
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
hooks:
- id: pyupgrade
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
exclude: (.github|.vscode|.devcontainer)
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
- repo: https://github.com/cdce8p/python-typing-update
rev: v0.6.0
hooks:
# Run `python-typing-update` hook manually from time to time
# to update python typing syntax.
# Will require manual work, before submitting changes!
# pre-commit run --hook-stage manual python-typing-update --all-files
- id: python-typing-update
stages: [manual]
args:
- --py311-plus
- --force
- --keep-updates
files: ^(/.+)?[^/]+\.py$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
args: [--strict, --ignore-missing-imports]
files: ^(/.+)?[^/]+\.py$
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.3
hooks:
- id: ruff
args:
- --fix
- id: ruff-format
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
args:
- --ignore-words-list=fro,hass
- --skip="./.*,*.csv,*.json,*.ambr"
- --quiet-level=2
exclude_types: [csv, json]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-executables-have-shebangs
stages: [manual]
- id: check-json
exclude: (.vscode|.devcontainer)
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
hooks:
- id: pyupgrade
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
hooks:
- id: yamllint
exclude: (.github|.vscode|.devcontainer)
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
hooks:
- id: prettier
- repo: https://github.com/cdce8p/python-typing-update
rev: v0.6.0
hooks:
# Run `python-typing-update` hook manually from time to time
# to update python typing syntax.
# Will require manual work, before submitting changes!
# pre-commit run --hook-stage manual python-typing-update --all-files
- id: python-typing-update
stages: [manual]
args:
- --py311-plus
- --force
- --keep-updates
files: ^(/.+)?[^/]+\.py$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
hooks:
- id: mypy
args: [--strict, --ignore-missing-imports]
files: ^(/.+)?[^/]+\.py$
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# yoto_ha

Home Assistant Integration for Yoto
5 changes: 2 additions & 3 deletions custom_components/yoto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

PLATFORMS: list[str] = [
Platform.BINARY_SENSOR,
#Platform.SENSOR,
#Platform.NUMBER,
# Platform.SENSOR,
# Platform.NUMBER,
]


async def async_setup(hass: HomeAssistant, config_entry: ConfigEntry):

return True


Expand Down
9 changes: 4 additions & 5 deletions custom_components/yoto/binary_sensor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Sensor for Yoto integration."""

from __future__ import annotations

from collections.abc import Callable
Expand Down Expand Up @@ -38,8 +39,8 @@ class YotoBinarySensorEntityDescription(BinarySensorEntityDescription):
key="online",
name="Online",
is_on=lambda player: player.engine_is_running,
#on_icon="mdi:engine",
#off_icon="mdi:engine-off",
# on_icon="mdi:engine",
# off_icon="mdi:engine-off",
),
)

Expand All @@ -56,9 +57,7 @@ async def async_setup_entry(
player: YotoPlayer = coordinator.yoto_manger.players[vehicle_id]
for description in SENSOR_DESCRIPTIONS:
if getattr(player, description.key, None) is not None:
entities.append(
YotoBinarySensor(coordinator, description, player)
)
entities.append(YotoBinarySensor(coordinator, description, player))
async_add_entities(entities)
return True

Expand Down
3 changes: 2 additions & 1 deletion custom_components/yoto/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow for Hyundai / Kia Connect integration."""

from __future__ import annotations

import hashlib
Expand Down Expand Up @@ -36,7 +37,7 @@

async def validate_input(hass: HomeAssistant, user_input: dict[str, Any]) -> Token:
"""Validate the user input allows us to connect."""

ym = await hass.async_add_executor_job(
YotoManager.login, user_input[CONF_USERNAME], user_input[CONF_PASSWORD]
)
Expand Down
11 changes: 3 additions & 8 deletions custom_components/yoto/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
"""Coordinator for yoto integration."""

from __future__ import annotations

from datetime import timedelta

import logging
from site import venv

from yoto_api import (
YotoManager,
)

from homeassistant.exceptions import ConfigEntryAuthFailed

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_PASSWORD,
CONF_SCAN_INTERVAL,
CONF_USERNAME,
)
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.core import HomeAssistant
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from homeassistant.util import dt as dt_util
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import (
DEFAULT_SCAN_INTERVAL,
Expand Down Expand Up @@ -59,7 +55,7 @@ async def _async_update_data(self):
# try:
await self.async_check_and_refresh_token()
# except AuthenticationError as AuthError:
#raise ConfigEntryAuthFailed(AuthError) from AuthError
# raise ConfigEntryAuthFailed(AuthError) from AuthError

await self.hass.async_add_executor_job(
self.yoto_manager.update_all_vehicles_with_cached_state
Expand All @@ -80,4 +76,3 @@ async def async_check_and_refresh_token(self):
await self.hass.async_add_executor_job(
self.yoto_manager.check_and_refresh_token
)

1 change: 1 addition & 0 deletions custom_components/yoto/entity.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Base Entity for Hyundai / Kia Connect integration."""

from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.helpers.entity import DeviceInfo

Expand Down
13 changes: 4 additions & 9 deletions custom_components/yoto/services.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Any, cast
from typing import cast


from homeassistant.const import ATTR_DEVICE_ID
Expand All @@ -12,9 +12,7 @@

SERVICE_UPDATE = "update"

SUPPORTED_SERVICES = (
SERVICE_UPDATE,
)
SUPPORTED_SERVICES = (SERVICE_UPDATE,)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -23,15 +21,12 @@
def async_setup_services(hass: HomeAssistant) -> bool:
"""Set up services for Yoto"""


async def async_handle_update(call):
_LOGGER.debug(f"Call:{call.data}")
coordinator = _get_coordinator_from_device(hass, call)
await coordinator.async_update_all()

services = {
SERVICE_UPDATE: async_handle_update
}
services = {SERVICE_UPDATE: async_handle_update}

for service in SUPPORTED_SERVICES:
hass.services.async_register(DOMAIN, service, services[service])
Expand Down Expand Up @@ -85,4 +80,4 @@ def _get_coordinator_from_device(
config_entry_unique_id = hass.config_entries.async_get_entry(
config_entry_id
).unique_id
return hass.data[DOMAIN][config_entry_unique_id]
return hass.data[DOMAIN][config_entry_unique_id]
12 changes: 6 additions & 6 deletions custom_components/yoto/services.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
update:
fields:
device_id:
update:
fields:
device_id:
required: false
selector:
device:
integration: yoto
selector:
device:
integration: yoto
33 changes: 33 additions & 0 deletions custom_components/yoto/strings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"config": {
"step": {
"user": {
"data": {
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]"
}
},
"reauth_confirm": {
"title": "[%key:component::yoto::config::step::reauth_confirm::title%]",
"description": "[%key:component::yoto::config::step::reauth_confirm::description%]"
}
},
"error": {
"invalid_auth": "[%key:common::config_flow::error::invalid_auth%]",
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reauth_successful": "[%key:common::config_flow::abort::reauth_successful%]"
}
},
"options": {
"step": {
"init": {
"data": {
"scan_interval": "[%key:component::yoto::options::step::init::data::scan_interval%]"
}
}
}
}
}
48 changes: 48 additions & 0 deletions custom_components/yoto/translations/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"title": "Yoto",
"config": {
"step": {
"user": {
"title": "Yoto - Authentication",
"description": "Set up your Yoto to integrate with Home Assistant.",
"data": {
"username": "Username",
"password": "Password"
}
},
"reauth_confirm": {
"title": "Yoto - Reauthentication",
"description": "Your account is unable to authenticate. Click Submit to re-setup."
}
},
"abort": {
"already_configured": "Device is already configured"
},
"error": {
"invalid_auth": "Login failed into Yoto Servers. Please use official app to logout and log back in and try again!",
"unknown": "Unexpected error"
}
},
"options": {
"step": {
"init": {
"title": "Yoto - Configuration",
"data": {
"scan_interval": "Scan Interval (min)"
}
}
}
},
"services": {
"update": {
"name": "Update",
"description": "Update player data from service cache",
"fields": {
"device_id": {
"name": "Player",
"description": "Target Player"
}
}
}
}
}

0 comments on commit df44835

Please sign in to comment.