Skip to content

Commit

Permalink
Merge pull request #33 from itchannel/active_dev
Browse files Browse the repository at this point in the history
Active dev
  • Loading branch information
itchannel committed Nov 23, 2020
2 parents 23b18f1 + 1d3b42c commit 1c711fd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 30 deletions.
12 changes: 3 additions & 9 deletions custom_components/fordpass/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
UpdateFailed,
)

from .const import DOMAIN, MANUFACTURER, VEHICLE, VIN, DEFAULT_UNIT, CONF_UNIT
from .const import CONF_UNIT, DEFAULT_UNIT, DOMAIN, MANUFACTURER, VEHICLE, VIN
from .fordpass_new import Vehicle

CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
Expand Down Expand Up @@ -72,14 +72,8 @@ async def async_refresh_status_service(service_call):


async def async_update_options(hass, config_entry):
options = {
CONF_UNIT: entry.data.get(
CONF_UNIT, DEFAULT_UNIT
)
}
hass.config_entries.async_update_entry(
config_entry, options=options
)
options = {CONF_UNIT: config_entry.data.get(CONF_UNIT, DEFAULT_UNIT)}
hass.config_entries.async_update_entry(config_entry, options=options)


def refresh_status(service, hass, coordinator):
Expand Down
22 changes: 10 additions & 12 deletions custom_components/fordpass/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import callback


from .const import DOMAIN, VIN, CONF_UNITS, CONF_UNIT, DEFAULT_UNIT # pylint:disable=unused-import

from .const import ( # pylint:disable=unused-import
CONF_UNIT,
CONF_UNITS,
DEFAULT_UNIT,
DOMAIN,
VIN,
)
from .fordpass_new import Vehicle

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -75,29 +79,23 @@ def async_get_options_flow(config_entry):
"""Get the options flow for this handler."""
return OptionsFlow(config_entry)

class OptionsFlow(config_entries.OptionsFlow):

class OptionsFlow(config_entries.OptionsFlow):
def __init__(self, config_entry: config_entries.ConfigEntry):
"""Initialize options flow."""
self.config_entry = config_entry


async def async_step_init(self, user_input=None):
if user_input is not None:
return self.async_create_entry(title="", data=user_input)
options = {
vol.Optional(
CONF_UNIT,
default=self.config_entry.options.get(
CONF_UNIT, DEFAULT_UNIT
),
default=self.config_entry.options.get(CONF_UNIT, DEFAULT_UNIT),
): vol.In(CONF_UNITS)
}

return self.async_show_form(
step_id="init", data_schema=vol.Schema(options)
)

return self.async_show_form(step_id="init", data_schema=vol.Schema(options))


class CannotConnect(exceptions.HomeAssistantError):
Expand Down
5 changes: 1 addition & 4 deletions custom_components/fordpass/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@
DEFAULT_UNIT = "metric"
CONF_UNIT = "units"

CONF_UNITS = [
"imperial",
"metric"
]
CONF_UNITS = ["imperial", "metric"]
6 changes: 5 additions & 1 deletion custom_components/fordpass/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class Lock(FordPassEntity, LockEntity):

def __init__(self, coordinator):
"""Initialize."""
super().__init__(device_id="fordpass_doorlock", name="fordpass_doorlock", coordinator=coordinator)
super().__init__(
device_id="fordpass_doorlock",
name="fordpass_doorlock",
coordinator=coordinator,
)

async def async_lock(self, **kwargs):
"""Locks the vehicle."""
Expand Down
11 changes: 8 additions & 3 deletions custom_components/fordpass/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from homeassistant.util import Throttle

from . import FordPassEntity
from .const import DOMAIN, CONF_UNIT
from .const import CONF_UNIT, DOMAIN

_LOGGER = logging.getLogger(__name__)

Expand All @@ -31,7 +31,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
async_add_entities([CarSensor(entry, snr, config_entry.options)], True)


class CarSensor(FordPassEntity, Entity,):
class CarSensor(
FordPassEntity,
Entity,
):
def __init__(self, coordinator, sensor, options):

self.sensor = sensor
Expand All @@ -44,7 +47,9 @@ def get_value(self, ftype):
if ftype == "state":
if self.sensor == "odometer":
if self.options[CONF_UNIT] == "imperial":
return round(float(self.coordinator.data[self.sensor]["value"]) / 1.60934)
return round(
float(self.coordinator.data[self.sensor]["value"]) / 1.60934
)
else:
return self.coordinator.data[self.sensor]["value"]
elif self.sensor == "fuel":
Expand Down
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- Added device_tracker type (fordpass_tracker)
- Added imperial or metric selection
- Change fuel reading to %
- Renamed lock entity from "lock.lock" to "lock.fordpass_lock"
- Renamed lock entity from "lock.lock" to "lock.fordpass_doorlock"


### Version 1.04
Expand Down

0 comments on commit 1c711fd

Please sign in to comment.