Skip to content

Commit

Permalink
Merge pull request #248 from itchannel/1.43
Browse files Browse the repository at this point in the history
1.43
  • Loading branch information
itchannel authored Feb 13, 2023
2 parents d041e98 + f31af10 commit 52a2862
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 20 deletions.
16 changes: 14 additions & 2 deletions custom_components/fordpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
VEHICLE,
VIN,
UPDATE_INTERVAL,
UPDATE_INTERVAL_DEFAULT
UPDATE_INTERVAL_DEFAULT,
COORDINATOR
)
from .fordpass_new import Vehicle

Expand Down Expand Up @@ -66,13 +67,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):

await coordinator.async_refresh() # Get initial data

fordpass_options_listener = entry.add_update_listener(options_update_listener)

if not entry.options:
await async_update_options(hass, entry)

if not coordinator.last_update_success:
raise ConfigEntryNotReady

hass.data[DOMAIN][entry.entry_id] = coordinator
hass.data[DOMAIN][entry.entry_id] = {
COORDINATOR : coordinator,
"fordpass_options_listener": fordpass_options_listener
}

for component in PLATFORMS:
hass.async_create_task(
Expand Down Expand Up @@ -115,6 +121,11 @@ async def async_update_options(hass, config_entry):
)
hass.config_entries.async_update_entry(config_entry, options=options)

async def options_update_listener(
hass: HomeAssistant, entry: ConfigEntry
):
_LOGGER.debug("OPTIONS CHANGE")
await hass.config_entries.async_reload(entry.entry_id)

def refresh_status(hass, service, coordinator):
_LOGGER.debug("Running Service")
Expand All @@ -141,6 +152,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
]
)
)
hass.data[DOMAIN][entry.entry_id]["fordpass_options_listener"]()
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

Expand Down
4 changes: 4 additions & 0 deletions custom_components/fordpass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
UPDATE_INTERVAL = "update_interval"
UPDATE_INTERVAL_DEFAULT = 900

COORDINATOR = "coordinator"


REGION = "region"

Expand Down Expand Up @@ -49,6 +51,8 @@
"remoteStartStatus": {"icon": "mdi:remote"},
"zoneLighting": {"icon": "mdi:spotlight-beam"},
"messages": {"icon": "mdi:message-text"},
"dieselSystemStatus": {"icon": "mdi:smoking-pipe"},
"exhaustFluidLevel": {"icon": "mdi:barrel"}
}

SWITCHES = {"ignition": {"icon": "hass:power"}, "guardmode": {"icon": "mdi:shield-key"}}
Expand Down
4 changes: 2 additions & 2 deletions custom_components/fordpass/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from homeassistant.components.device_tracker.config_entry import TrackerEntity

from . import FordPassEntity
from .const import DOMAIN
from .const import DOMAIN, COORDINATOR

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add the Entities from the config."""
entry = hass.data[DOMAIN][config_entry.entry_id]
entry = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]

# Added a check to see if the car supports GPS
if entry.data["gps"] != None:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/fordpass/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from homeassistant.components.lock import LockEntity

from . import FordPassEntity
from .const import DOMAIN
from .const import DOMAIN, COORDINATOR

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add the lock from the config."""
entry = hass.data[DOMAIN][config_entry.entry_id]
entry = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]

locks = [Lock(entry)]
async_add_entities(locks, False)
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 @@ -5,7 +5,7 @@
"integration_type": "device",
"documentation": "https://github.com/itchannel/fordpass-ha",
"issue_tracker": "https://github.com/itchannel/fordpass-ha/issues",
"version": "0.1.42",
"version": "0.1.43",
"requirements": [],
"ssdp": [],
"zeroconf": [],
Expand Down
44 changes: 33 additions & 11 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,34 @@
)

from . import FordPassEntity
from .const import CONF_DISTANCE_UNIT, CONF_PRESSURE_UNIT, DOMAIN, SENSORS
from .const import CONF_DISTANCE_UNIT, CONF_PRESSURE_UNIT, DOMAIN, SENSORS, COORDINATOR


_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add the Entities from the config."""
entry = hass.data[DOMAIN][config_entry.entry_id]

entry = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]
sensors = []
for key, value in SENSORS.items():
sensor = CarSensor(entry, key, config_entry.options)
# Add support for only adding compatible sensors for the given vehicle
if key == "zoneLighting":
if "zoneLighting" in sensor.coordinator.data:
async_add_entities([sensor], True)
sensors.append(sensor)
elif key == "elVeh":
if sensor.coordinator.data["elVehDTE"] != None:
async_add_entities([sensor], True)
sensors.append(sensor)
elif key == "dieselSystemStatus":
if "dieselSystemStatus" in sensor.coordinator.data and sensor.coordinator.data["dieselSystemStatus"]["filterRegenerationStatus"] != None:
sensors.append(sensor)
elif key == "exhaustFluidLevel":
if "exhaustFluidLevel" in sensor.coordinator.data and sensor.coordinator.data["dieselSystemStatus"]["exhaustFluidLevel"] != None:
sensors.append(sensor)
else:
async_add_entities([sensor], True)

sensors.append(sensor)
async_add_entities(sensors, True)

class CarSensor(
FordPassEntity,
Expand Down Expand Up @@ -143,6 +149,16 @@ def get_value(self, ftype):
return None
else:
return len(self.coordinator.data["messages"])
elif self.sensor == "dieselSystemStatus":
if self.coordinator.data["dieselSystemStatus"]["filterRegenerationStatus"] != None:
return self.coordinator.data["dieselSystemStatus"]["filterRegenerationStatus"]
else:
return "Not Supported"
elif self.sensor == "exhaustFluidLevel":
if "value" in self.coordinator.data["dieselSystemStatus"]["exhaustFluidLevel"]:
return self.coordinator.data["dieselSystemStatus"]["exhaustFluidLevel"]["value"]
else:
return "Not Supported"
elif ftype == "measurement":
if self.sensor == "odometer":
if self.fordoptions[CONF_DISTANCE_UNIT] == "mi":
Expand Down Expand Up @@ -179,6 +195,8 @@ def get_value(self, ftype):
return None
elif self.sensor == "messages":
return "Messages"
elif self.sensor == "exhaustFluidLevel":
return "%"
elif ftype == "attribute":
if self.sensor == "odometer":
return self.coordinator.data[self.sensor].items()
Expand Down Expand Up @@ -219,7 +237,7 @@ def get_value(self, ftype):
decimal = 0
tirepress = {}
for key, value in self.coordinator.data["TPMS"].items():
if "TirePressure" in key and value is not None and value is not '':
if "TirePressure" in key and value is not None and value != '':
if "recommended" in key:
tirepress[key] = round(float(value["value"]) * rval, decimal)
else:
Expand Down Expand Up @@ -392,6 +410,10 @@ def get_value(self, ftype):

messages[value["messageSubject"]] = value["createdDate"]
return messages
elif self.sensor == "dieselSystemStatus":
return self.coordinator.data["dieselSystemStatus"]
elif self.sensor == "exhaustFluidLevel":
return self.coordinator.data["dieselSystemStatus"]

@property
def name(self):
Expand Down Expand Up @@ -420,9 +442,9 @@ def icon(self):
@property
def state_class(self):
if "state_class" in SENSORS[self.sensor]:
if SENSORS[self.sensor]["state_class"] is "total":
if SENSORS[self.sensor]["state_class"] == "total":
return SensorStateClass.TOTAL
elif SENSORS[self.sensor]["state_class"] is "measurement":
elif SENSORS[self.sensor]["state_class"] == "measurement":
return SensorStateClass.MEASUREMENT
else:
return None
Expand All @@ -432,7 +454,7 @@ def state_class(self):
@property
def device_class(self):
if "device_class" in SENSORS[self.sensor]:
if SENSORS[self.sensor]["device_class"] is "distance":
if SENSORS[self.sensor]["device_class"] == "distance":
return SensorDeviceClass.DISTANCE
else:
return None
4 changes: 2 additions & 2 deletions custom_components/fordpass/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
from homeassistant.components.switch import SwitchEntity

from . import FordPassEntity
from .const import DOMAIN, SWITCHES
from .const import DOMAIN, SWITCHES, COORDINATOR

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Add the Switch from the config."""
entry = hass.data[DOMAIN][config_entry.entry_id]
entry = hass.data[DOMAIN][config_entry.entry_id][COORDINATOR]

# switches = [Switch(entry)]
# async_add_entities(switches, False)
Expand Down
4 changes: 4 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## **Changelog**
### Version 1.43
- Add DPF status on supported vehicles
- Incorrect vehicle refresh time (@ronytomen)
- Refresh integration automatticly on options changes
### Version 1.42
- Fix incorrect tire pressure units (Thanks @costr for debugging)
### Version 1.41
Expand Down

0 comments on commit 52a2862

Please sign in to comment.