Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #387 from Thomas55555/low_energy-as-default
Browse files Browse the repository at this point in the history
low_energy as default poll cycle
  • Loading branch information
Thomas55555 authored Apr 3, 2023
2 parents 7f67dea + dfd7d5d commit d05d898
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 13 deletions.
5 changes: 3 additions & 2 deletions custom_components/husqvarna_automower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
async_get_config_entry_implementation,
)

from .const import DOMAIN, PLATFORMS, STARTUP_MESSAGE
from .const import DOMAIN, PLATFORMS, STARTUP_MESSAGE, DISABLE_LE

_LOGGER = logging.getLogger(__name__)

Expand All @@ -28,7 +28,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
for k in ap_storage_data:
api_key = ap_storage_data[k]["client_id"]
access_token = entry.data.get(CONF_TOKEN)
session = aioautomower.AutomowerSession(api_key, access_token)
low_energy = not entry.options.get(DISABLE_LE)
session = aioautomower.AutomowerSession(api_key, access_token, low_energy)
session.register_token_callback(
lambda token: hass.config_entries.async_update_entry(
entry,
Expand Down
9 changes: 5 additions & 4 deletions custom_components/husqvarna_automower/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ async def async_setup_entry(
) -> None:
"""Set up select platform."""
session = hass.data[DOMAIN][entry.entry_id]
async_add_entities(
AutomowerCamera(session, idx, entry)
for idx, ent in enumerate(session.data["data"])
)
if entry.options.get(ENABLE_CAMERA):
async_add_entities(
AutomowerCamera(session, idx, entry)
for idx, ent in enumerate(session.data["data"])
)


class AutomowerCamera(HusqvarnaAutomowerStateMixin, Camera, AutomowerEntity):
Expand Down
14 changes: 9 additions & 5 deletions custom_components/husqvarna_automower/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .const import (
DOMAIN,
DISABLE_LE,
ENABLE_CAMERA,
GPS_BOTTOM_RIGHT,
GPS_TOP_LEFT,
Expand Down Expand Up @@ -97,6 +98,7 @@ def __init__(self, config_entry: config_entries.ConfigEntry) -> None:
self.config_entry = config_entry

self.camera_enabled = self.config_entry.options.get(ENABLE_CAMERA, False)
self.disable_le = self.config_entry.options.get(DISABLE_LE, True)
self.map_top_left_coord = self.config_entry.options.get(GPS_TOP_LEFT, "")
if self.map_top_left_coord != "":
self.map_top_left_coord = ",".join(
Expand All @@ -123,14 +125,16 @@ async def async_step_init(self, user_input=None):
"""Enable / Disable the camera."""
if user_input:
if user_input.get(ENABLE_CAMERA):
self.options[ENABLE_CAMERA] = True
self.options[ENABLE_CAMERA] = user_input.get(ENABLE_CAMERA)
return await self.async_step_config()
self.options[ENABLE_CAMERA] = False
return await self._update_camera_config()
self.options[ENABLE_CAMERA] = user_input.get(ENABLE_CAMERA)
self.options[DISABLE_LE] = user_input.get(DISABLE_LE)
return await self._update_config()

data_schema = vol.Schema(
{
vol.Required(ENABLE_CAMERA, default=self.camera_enabled): bool,
vol.Required(DISABLE_LE, default=self.disable_le): bool,
}
)
return self.async_show_form(step_id="init", data_schema=data_schema)
Expand All @@ -153,7 +157,7 @@ async def async_step_config(self, user_input=None):

self.options[MOWER_IMG_PATH] = user_input.get(MOWER_IMG_PATH)
self.options[MAP_IMG_PATH] = user_input.get(MAP_IMG_PATH)
return await self._update_camera_config()
return await self._update_config()

data_schema = vol.Schema(
{
Expand All @@ -167,6 +171,6 @@ async def async_step_config(self, user_input=None):
)
return self.async_show_form(step_id="config", data_schema=data_schema)

async def _update_camera_config(self):
async def _update_config(self):
"""Update config entry options."""
return self.async_create_entry(title="", data=self.options)
1 change: 1 addition & 0 deletions custom_components/husqvarna_automower/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
HUSQVARNA_URL = "https://developer.husqvarnagroup.cloud/login"
OAUTH2_AUTHORIZE = "https://api.authentication.husqvarnagroup.dev/v1/oauth2/authorize"
OAUTH2_TOKEN = "https://api.authentication.husqvarnagroup.dev/v1/oauth2/token"
DISABLE_LE = "disable_le"

# Platforms
PLATFORMS = [
Expand Down
5 changes: 3 additions & 2 deletions custom_components/husqvarna_automower/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"step": {
"init": {
"data": {
"enable_camera": "Enable Map Camera"
"enable_camera": "Enable Map Camera",
"disable_le": "Disbale Low Energy Mode"
},
"description": "Enable Map Camera",
"description": "Select Integration Options",
"title": "Husqvarna Automower Options"
},
"config": {
Expand Down

0 comments on commit d05d898

Please sign in to comment.