Skip to content

Commit

Permalink
Merge pull request #460 from itchannel/1.64
Browse files Browse the repository at this point in the history
1.64
  • Loading branch information
itchannel committed Jan 2, 2024
2 parents 306900b + f49c780 commit fbd57c2
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
9 changes: 7 additions & 2 deletions custom_components/fordpass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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"}}
Expand Down
4 changes: 4 additions & 0 deletions custom_components/fordpass/fordpass_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from homeassistant import exceptions

_LOGGER = logging.getLogger(__name__)
defaultHeaders = {
Expand Down Expand Up @@ -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"])




Expand Down
2 changes: 1 addition & 1 deletion custom_components/fordpass/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"loggers": ["custom_components.fordpass"],
"requirements": [],
"ssdp": [],
"version": "0.1.63",
"version": "0.1.64",
"zeroconf": []
}
26 changes: 25 additions & 1 deletion custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {}):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
5 changes: 4 additions & 1 deletion custom_components/fordpass/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit fbd57c2

Please sign in to comment.