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

feat: allow state in set_override to be optional #128

Merged
merged 10 commits into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 8 additions & 10 deletions custom_components/openevse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,24 @@
import logging
from datetime import timedelta

import voluptuous as vol

import homeassistant.helpers.device_registry as dr
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import Config, HomeAssistant, callback, ServiceCall
from homeassistant.core import Config, HomeAssistant, ServiceCall, callback
from homeassistant.exceptions import ConfigEntryNotReady
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
from openevsehttp.__main__ import OpenEVSE
from openevsehttp.exceptions import MissingSerial

from .const import (
ATTR_DEVICE_ID,
ATTR_STATE,
ATTR_AUTO_RELEASE,
ATTR_CHARGE_CURRENT,
ATTR_MAX_CURRENT,
ATTR_DEVICE_ID,
ATTR_ENERGY_LIMIT,
ATTR_MAX_CURRENT,
ATTR_STATE,
ATTR_TIME_LIMIT,
ATTR_AUTO_RELEASE,
BINARY_SENSORS,
CONF_NAME,
COORDINATOR,
Expand All @@ -36,8 +35,7 @@
SENSOR_TYPES,
VERSION,
)

from .services import set_overrride, clear_override
from .services import clear_override, set_overrride

SERVICE_SET_OVERRIDE = "set_override"
SERVICE_CLEAR_OVERRIDE = "clear_override"
Expand Down Expand Up @@ -82,7 +80,7 @@ async def _set_override(service: ServiceCall) -> None:
schema=vol.Schema(
{
vol.Required(ATTR_DEVICE_ID): vol.Coerce(str),
vol.Required(ATTR_STATE): vol.Coerce(str),
vol.Optional(ATTR_STATE): vol.Coerce(str),
vol.Optional(ATTR_CHARGE_CURRENT): vol.All(
vol.Coerce(int), vol.Range(min=1, max=48)
),
Expand Down
1 change: 1 addition & 0 deletions custom_components/openevse/button.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Support for OpenEVSE buttons."""
from __future__ import annotations

import logging

from homeassistant.components.button import (
Expand Down
8 changes: 3 additions & 5 deletions custom_components/openevse/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
BinarySensorDeviceClass,
BinarySensorEntityDescription,
)
from homeassistant.components.button import (
ButtonDeviceClass,
ButtonEntityDescription,
)
from homeassistant.components.button import ButtonDeviceClass, ButtonEntityDescription
from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntityDescription,
Expand Down Expand Up @@ -310,10 +307,11 @@
),
"max_current_soft": OpenEVSESelectEntityDescription(
name="Max Current",
key="max_current_soft",
key="current_capacity",
default_options=None,
command="set_current",
entity_category=EntityCategory.CONFIG,
entity_registry_enabled_default=False,
),
"divertmode": OpenEVSESelectEntityDescription(
name="Divert Mode",
Expand Down
5 changes: 1 addition & 4 deletions custom_components/openevse/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntry

from .const import (
COORDINATOR,
DOMAIN,
)
from .const import COORDINATOR, DOMAIN

REDACT_KEYS = {CONF_PASSWORD}

Expand Down
4 changes: 3 additions & 1 deletion custom_components/openevse/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"domain": "openevse",
"name": "OpenEVSE",
"documentation": "https://www.home-assistant.io/integrations/openevse",
"requirements": ["python-openevse-http==0.1.35"],
"issue_tracker": "https://github.com/firstof9/openevse/issues",
"requirements": ["python-openevse-http==0.1.37"],
"after_dependencies": ["zeroconf"],
"zeroconf": ["_openevse._tcp.local."],
"codeowners": ["@firstof9"],
"iot_class": "local_push",
Expand Down
2 changes: 1 addition & 1 deletion custom_components/openevse/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def available(self) -> bool:

def get_options(self) -> list[str]:
"""Return a set of selectable options."""
if self._type == "max_current_soft":
if self._type == "current_capacity":
min = self.coordinator.data["min_amps"]
max = self.coordinator.data["max_amps"] + 1
options = list([str(item) for item in range(min, max)])
Expand Down
18 changes: 8 additions & 10 deletions custom_components/openevse/services.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""Services for OpenEVSE."""
from __future__ import annotations

import logging

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import async_get as async_get_device_registry

from .const import (
DOMAIN,
MANAGER,
ATTR_DEVICE_ID,
ATTR_STATE,
ATTR_AUTO_RELEASE,
ATTR_CHARGE_CURRENT,
ATTR_MAX_CURRENT,
ATTR_DEVICE_ID,
ATTR_ENERGY_LIMIT,
ATTR_MAX_CURRENT,
ATTR_STATE,
ATTR_TIME_LIMIT,
ATTR_AUTO_RELEASE,
DOMAIN,
MANAGER,
)

_LOGGER = logging.getLogger(__name__)
Expand All @@ -37,9 +37,7 @@ async def set_overrride(
if ATTR_STATE in data:
state = data[ATTR_STATE]
else:
_LOGGER.error("Missing state value!")
raise ValueError

state = None
if ATTR_CHARGE_CURRENT in data:
charge_current = data[ATTR_CHARGE_CURRENT]
else:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/openevse/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set_override:
state:
name: State
description: Enable or Disable Override
required: true
required: false
default: disabled
example: disabled
selector:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/openevse/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import logging
from typing import Any, cast

from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_NAME
from homeassistant.helpers.update_coordinator import CoordinatorEntity

from . import (
CommandFailed,
Expand Down
1 change: 0 additions & 1 deletion custom_components/openevse/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
UpdateEntity,
UpdateEntityFeature,
)

from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback
Expand Down
2 changes: 0 additions & 2 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"name": "OpenEVSE",
"issue_tracker": "https://github.com/firstof9/openevse/issues",
"iot_class": "Local Polling",
"homeassistant": "0.118.0",
"zip_release": true,
"filename": "openevse.zip",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-openevse-http==0.1.35
python-openevse-http==0.1.37
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ isort==5.11.4
pylint==2.15.9
tox==4.2.3
pytest==7.2.0
aiohttp_cors