diff --git a/custom_components/fordpass/const.py b/custom_components/fordpass/const.py index 35320cf..ba696d7 100644 --- a/custom_components/fordpass/const.py +++ b/custom_components/fordpass/const.py @@ -40,7 +40,7 @@ "ignitionStatus": {"icon": "hass:power", "api_key": "ignitionStatus"}, "doorStatus": {"icon": "mdi:car-door", "api_key": "doorStatus"}, "windowPosition": {"icon": "mdi:car-door", "api_key": "windowStatus"}, - "lastRefresh": {"icon": "mdi:clock", "device_class": "timestamp", "api_key": "lastRefresh"}, + "lastRefresh": {"icon": "mdi:clock", "device_class": "timestamp", "api_key": "lastRefresh" , "sensor_type": "single"}, "elVeh": {"icon": "mdi:ev-station", "api_key": "xevBatteryRange", "device_class": "distance", "state_class": "measurement", "measurement": "km"}, "elVehCharging": {"icon": "mdi:ev-station", "api_key": "xevBatteryChargeDisplayStatus"}, "speed": {"icon": "mdi:speedometer", "device_class": "speed", "state_class": "measurement", "api_key": "speed", "measurement": "km/h"}, @@ -55,9 +55,14 @@ # }, "remoteStartStatus": {"icon": "mdi:remote", "api_key": "remoteStartCountdownTimer"}, # "zoneLighting": {"icon": "mdi:spotlight-beam"}, - "messages": {"icon": "mdi:message-text", "api_key": "messages", "measurement": "messages"}, + "messages": {"icon": "mdi:message-text", "api_key": "messages", "measurement": "messages", "sensor_type": "single"}, "dieselSystemStatus": {"icon": "mdi:smoking-pipe", "api_key": "dieselExhaustFilterStatus"}, "exhaustFluidLevel": {"icon": "mdi:barrel", "api_key": "dieselExhaustFluidLevel", "measurement": "%"}, + # Debug Sensors (Disabled by default) + "events": {"icon": "mdi:calendar", "api_key": "events", "sensor_type": "single", "debug": True}, + "metrics": {"icon": "mdi:chart-line", "api_key": "metrics", "sensor_type": "single", "debug": True}, + "states": {"icon": "mdi:car", "api_key": "states", "sensor_type": "single", "debug": True}, + "vehicles": {"icon": "mdi:car-multiple", "api_key": "vehicles", "sensor_type": "single", "debug": True}, } SWITCHES = {"ignition": {"icon": "hass:power"}, "guardmode": {"icon": "mdi:shield-key"}} diff --git a/custom_components/fordpass/fordpass_new.py b/custom_components/fordpass/fordpass_new.py index 5e61707..229d1eb 100644 --- a/custom_components/fordpass/fordpass_new.py +++ b/custom_components/fordpass/fordpass_new.py @@ -12,6 +12,7 @@ from requests.adapters import HTTPAdapter from urllib3.util.retry import Retry +from homeassistant import exceptions _LOGGER = logging.getLogger(__name__) defaultHeaders = { @@ -163,6 +164,9 @@ def auth2_step1(self): cookie_dict = step1_session.cookies.get_dict() _LOGGER.debug(cookie_dict) + if step1post.status_code == 400: + raise exceptions.HomeAssistantError(step1post.json()["message"]) + diff --git a/custom_components/fordpass/manifest.json b/custom_components/fordpass/manifest.json index ba3c203..2a918fe 100644 --- a/custom_components/fordpass/manifest.json +++ b/custom_components/fordpass/manifest.json @@ -12,6 +12,6 @@ "loggers": ["custom_components.fordpass"], "requirements": [], "ssdp": [], - "version": "0.1.63", + "version": "0.1.64", "zeroconf": [] } \ No newline at end of file diff --git a/custom_components/fordpass/sensor.py b/custom_components/fordpass/sensor.py index 8373fd3..b582fbc 100644 --- a/custom_components/fordpass/sensor.py +++ b/custom_components/fordpass/sensor.py @@ -32,8 +32,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): sensor = CarSensor(entry, key, config_entry.options) api_key = value["api_key"] api_class = value.get("api_class", None) + sensor_type = value.get("sensor_type", None) string = isinstance(api_key, str) - if string and api_key == "messages" or api_key == "lastRefresh": + if string and sensor_type == "single": sensors.append(sensor) elif string: if api_key and api_class and api_key in sensor.coordinator.data.get(api_class, {}): @@ -159,6 +160,14 @@ def get_value(self, ftype): return "DISABLED" else: return state + if self.sensor == "events": + return len(self.events) + if self.sensor == "states": + return len(self.states) + if self.sensor == "vehicles": + return len(self.coordinator.data.get("vehicles", {})) + if self.sensor == "metrics": + return len(self.data) return None if ftype == "measurement": return SENSORS.get(self.sensor, {}).get("measurement", None) @@ -470,6 +479,14 @@ def get_value(self, ftype): if value.get("value") is not None: alerts[key] = value["value"] return alerts or None + if self.sensor == "events": + return self.events + if self.sensor == "states": + return self.states + if self.sensor == "vehicles": + return self.coordinator.data.get("vehicles", {}) + if self.sensor == "metrics": + return self.data return None @@ -537,3 +554,10 @@ def device_class(self): if SENSORS[self.sensor]["device_class"] == "speed": return SensorDeviceClass.SPEED return None + + @property + def entity_registry_enabled_default(self): + """Return if entity should be enabled when first added to the entity registry.""" + if "debug" in SENSORS[self.sensor]: + return False + return True diff --git a/custom_components/fordpass/translations/en.json b/custom_components/fordpass/translations/en.json index ebfbcd9..3695d66 100644 --- a/custom_components/fordpass/translations/en.json +++ b/custom_components/fordpass/translations/en.json @@ -16,7 +16,10 @@ "password": "FordPass Password", "username": "FordPass Username (Email)", "region" : "FordPass Region" - } + }, + "data_description": { + "username": "If using a mobile instead of email please enter your number (minus initial 0) also include + and the country code (e.g. +99123456789)" + } }, "vehicle": { "title": "Select vehicle to add", diff --git a/info.md b/info.md index 0caa938..8cb35db 100644 --- a/info.md +++ b/info.md @@ -1,4 +1,7 @@ ## **Changelog** +### Version 1.64 +- Add helper text for initial login when using a mobile number +- Added sensors containing all returned data from API (Disabled by default in HA) can be used for templates and other automations/research ### Version 1.63 - Reworked authentication to use login.ford.com ### Version 1.62