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

remove depracated features #511

Merged
merged 9 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from 8 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
27 changes: 0 additions & 27 deletions custom_components/husqvarna_automower/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,31 +277,4 @@
set(ELECTRONIC_CUTTING_HEIGHT_SUPPORT) - set(NO_SUPPORT_FOR_CHANGING_CUTTING_HEIGHT)
)

MWR_STATE_TO_STATUS = {
"UNKNOWN": "unknown",
"NOT_APPLICABLE": "not_applicable",
"PAUSED": "paused",
"WAIT_UPDATING": "updating",
"WAIT_POWER_UP": "powering_up",
"OFF": "off",
"STOPPED": "stopped",
}

MWR_ACTIVITY_TO_STATUS = {
"UNKNOWN": "unknown",
"NOT_APPLICABLE": "not_applicable",
"MOWING": "mowing",
"GOING_HOME": "going_to_charging_station",
"LEAVING": "leaving_charging_station",
"PARKED_IN_CS": "parked",
"STOPPED_IN_GARDEN": "stopped",
}

MWR_RES_REASON_TO_STATUS = {
"PARK_OVERRIDE": "park_override",
"SENSOR": "weather_timer",
"DAILY_LIMIT": "daily_limit",
"NOT_APPLICABLE": "parked_until_further_notice",
}

CURRENT_CONFIG_VER = 4
120 changes: 4 additions & 116 deletions custom_components/husqvarna_automower/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from aiohttp import ClientResponseError
from dateutil import tz
from homeassistant.components.vacuum import (
ATTR_STATUS,
STATE_CLEANING,
STATE_DOCKED,
STATE_ERROR,
Expand Down Expand Up @@ -83,123 +82,14 @@ async def test_vacuum_extra_state_attributes(hass: HomeAssistant):
coordinator = hass.data[DOMAIN]["automower_test"]
vacuum = HusqvarnaAutomowerEntity(coordinator, MWR_ONE_IDX)

def set_state(state: str):
"""Set new state"""
coordinator.session.data["data"][MWR_ONE_IDX]["attributes"]["mower"][
"state"
] = state

def set_activity(activity: str):
"""Set new state"""
coordinator.session.data["data"][MWR_ONE_IDX]["attributes"]["mower"][
"activity"
] = activity

def set_restricted_reason(reason: str):
"""Set new restricted reason"""
coordinator.session.data["data"][MWR_ONE_IDX]["attributes"]["planner"][
"restrictedReason"
] = reason

assert vacuum._attr_unique_id == MWR_ONE_ID
assert vacuum.extra_state_attributes == {"action": None}

Thomas55555 marked this conversation as resolved.
Show resolved Hide resolved
set_state("UNKNOWN")
assert vacuum.extra_state_attributes == {"action": None, "status": "unknown"}

set_state("NOT_APPLICABLE")
assert vacuum.extra_state_attributes == {"action": None, "status": "not_applicable"}

set_state("PAUSED")
assert vacuum.extra_state_attributes == {"action": None, "status": "paused"}

set_state("IN_OPERATION")
set_activity("UNKNOWN")
assert vacuum.extra_state_attributes == {"action": None, "status": "unknown"}

set_activity("NOT_APPLICABLE")
assert vacuum.extra_state_attributes == {"action": None, "status": "not_applicable"}

set_activity("MOWING")
assert vacuum.extra_state_attributes == {"action": None, "status": "mowing"}

set_activity("GOING_HOME")
assert vacuum.extra_state_attributes == {
"action": None,
"status": "going_to_charging_station",
}

set_activity("CHARGING")
assert vacuum.extra_state_attributes == {
"action": None,
"status": "Charging, next start: Mon 19:00",
}

set_activity("LEAVING")
assert vacuum.extra_state_attributes == {
"action": None,
"status": "leaving_charging_station",
}

set_activity("PARKED_IN_CS")
assert vacuum.extra_state_attributes == {"action": None, "status": "parked"}

set_activity("STOPPED_IN_GARDEN")
assert vacuum.extra_state_attributes == {"action": None, "status": "stopped"}

set_state("WAIT_UPDATING")
assert vacuum.extra_state_attributes == {"action": None, "status": "updating"}

set_state("WAIT_POWER_UP")
assert vacuum.extra_state_attributes == {"action": None, "status": "powering_up"}

set_state("RESTRICTED")
set_restricted_reason("WEEK_SCHEDULE")
assert vacuum.extra_state_attributes == {
"action": None,
"status": "Schedule, next start: Mon 19:00",
}

set_restricted_reason("PARK_OVERRIDE")
assert vacuum.extra_state_attributes == {"action": None, "status": "park_override"}

set_restricted_reason("SENSOR")
assert vacuum.extra_state_attributes == {"action": None, "status": "weather_timer"}

set_restricted_reason("DAILY_LIMIT")
assert vacuum.extra_state_attributes == {"action": None, "status": "daily_limit"}

set_restricted_reason("NOT_APPLICABLE")
assert vacuum.extra_state_attributes == {
"action": None,
"status": "parked_until_further_notice",
}

set_state("OFF")
assert vacuum.extra_state_attributes == {"action": None, "status": "off"}

set_state("STOPPED")
assert vacuum.extra_state_attributes == {"action": None, "status": "stopped"}

set_state("ERROR")
assert vacuum.extra_state_attributes == {
"action": None,
"status": "Unexpected error",
}

set_state("FATAL_ERROR")
assert vacuum.extra_state_attributes == {
"action": None,
"status": "Unexpected error",
}

set_state("ERROR_AT_POWER_UP")
assert vacuum.extra_state_attributes == {
"action": None,
"status": "Unexpected error",
coordinator.session.data["data"][MWR_ONE_IDX]["attributes"]["planner"] = {
"override": {"action": "Test_Action"}
}

set_state("BAD_ERROR")
assert vacuum.extra_state_attributes == {"action": None, "status": None}
assert vacuum.extra_state_attributes == {"action": "test_action"}


@pytest.mark.asyncio
Expand Down Expand Up @@ -313,13 +203,11 @@ def set_error_code(code: str):
] = code

assert vacuum._attr_unique_id == MWR_ONE_ID
assert vacuum.error is None

set_state("STOPPED_IN_GARDEN")
set_activity("UNKNOWN")
set_error_code(0)
assert vacuum.state == STATE_ERROR
assert vacuum.error == "Unexpected error"


@pytest.mark.asyncio
Expand Down
64 changes: 1 addition & 63 deletions custom_components/husqvarna_automower/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from aiohttp import ClientResponseError
from homeassistant.components.schedule import DOMAIN as SCHEDULE_DOMAIN
from homeassistant.components.vacuum import (
ATTR_STATUS,
STATE_CLEANING,
STATE_DOCKED,
STATE_ERROR,
Expand All @@ -24,26 +23,15 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.storage import Store

from .const import (
DOMAIN,
ERROR_ACTIVITIES,
ERROR_STATES,
ERRORCODES,
MWR_ACTIVITY_TO_STATUS,
MWR_RES_REASON_TO_STATUS,
MWR_STATE_TO_STATUS,
WEEKDAYS,
)
from .const import DOMAIN, ERROR_ACTIVITIES, WEEKDAYS
from .entity import AutomowerEntity

SUPPORT_STATE_SERVICES = (
VacuumEntityFeature.STATE
| VacuumEntityFeature.BATTERY
| VacuumEntityFeature.PAUSE
| VacuumEntityFeature.RETURN_HOME
| VacuumEntityFeature.SEND_COMMAND
| VacuumEntityFeature.START
| VacuumEntityFeature.STATUS
| VacuumEntityFeature.STOP
)

Expand Down Expand Up @@ -114,17 +102,6 @@ def available(self) -> bool:
available = self.get_mower_attributes()["metadata"]["connected"]
return available

@property
def battery_level(self) -> int:
"""Return the current battery level of the mower."""
return max(
0,
min(
100,
AutomowerEntity.get_mower_attributes(self)["battery"]["batteryPercent"],
),
)

@property
def state(self) -> str:
"""Return the state of the mower."""
Expand Down Expand Up @@ -158,52 +135,13 @@ def state(self) -> str:
) or mower_attributes["mower"]["activity"] in ERROR_ACTIVITIES:
return STATE_ERROR

@property
def error(self) -> str:
"""Define an error message if the vacuum is in STATE_ERROR."""
if self.state == STATE_ERROR:
mower_attributes = AutomowerEntity.get_mower_attributes(self)
errorcode = mower_attributes["mower"]["errorCode"]
return ERRORCODES.get(errorcode, f"error_{errorcode}")
return None

def __get_status(self) -> str:
mower_attributes = AutomowerEntity.get_mower_attributes(self)
next_start_short = ""
if mower_attributes["planner"]["nextStartTimestamp"] != 0:
next_start_dt_obj = AutomowerEntity.datetime_object(
self, mower_attributes["planner"]["nextStartTimestamp"]
)
next_start_short = next_start_dt_obj.strftime(", next start: %a %H:%M")
if mower_attributes["mower"]["state"] in MWR_STATE_TO_STATUS:
return MWR_STATE_TO_STATUS.get(mower_attributes["mower"]["state"])
if mower_attributes["mower"]["state"] == "IN_OPERATION":
if mower_attributes["mower"]["activity"] in MWR_ACTIVITY_TO_STATUS:
return MWR_ACTIVITY_TO_STATUS.get(mower_attributes["mower"]["activity"])
if mower_attributes["mower"]["activity"] == "CHARGING":
return f"Charging{next_start_short}"
if mower_attributes["mower"]["state"] == "RESTRICTED":
if (
mower_attributes["planner"]["restrictedReason"]
in MWR_RES_REASON_TO_STATUS
):
return MWR_RES_REASON_TO_STATUS.get(
mower_attributes["planner"]["restrictedReason"]
)
if mower_attributes["planner"]["restrictedReason"] == "WEEK_SCHEDULE":
return f"Schedule{next_start_short}"
if mower_attributes["mower"]["state"] in ERROR_STATES:
return ERRORCODES.get(mower_attributes["mower"]["errorCode"])
return None

@property
def extra_state_attributes(self) -> dict:
"""Return the specific state attributes of this mower."""
mower_attributes = AutomowerEntity.get_mower_attributes(self)
action = mower_attributes["planner"]["override"]["action"]
action = action.lower() if action is not None else action
return {
ATTR_STATUS: self.__get_status(),
"action": action,
}

Expand Down