Skip to content

Commit

Permalink
style: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jul 19, 2020
1 parent b6d5279 commit 7ac9c0b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 53 deletions.
46 changes: 24 additions & 22 deletions teslajsonpy/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
https://github.com/zabuldon/teslajsonpy
"""
import logging
from typing import Dict, Text
from typing import Dict, Optional, Text

_LOGGER = logging.getLogger(__name__)

Expand All @@ -33,45 +33,45 @@ def __init__(self, data, controller):
None
"""
self._id = data["id"]
self._vehicle_id = data["vehicle_id"]
self._display_name = data["display_name"]
self._vin = data["vin"]
self._id: int = data["id"]
self._vehicle_id: int = data["vehicle_id"]
self._display_name: Text = data["display_name"]
self._vin: Text = data["vin"]
self._state = data["state"]
self._car_type = f"Model {str(self._vin[3]).upper()}"
self._car_version = ""
self._sentry_mode_available = (
self._car_type: Text = f"Model {str(self._vin[3]).upper()}"
self._car_version: Text = ""
self._sentry_mode_available: bool = (
"vehicle_state" in data
and "sentry_mode_available" in data["vehicle_state"]
and data["vehicle_state"]["sentry_mode_available"]
)
self._controller = controller
self.should_poll = True
self.type = "device"
self.should_poll: bool = True
self.type: Text = "device"
self.attrs: Dict[Text, Text] = {}

def _name(self):
def _name(self) -> Text:
return (
"{} {}".format(self._display_name, self.type)
if self._display_name is not None and self._display_name != self._vin[-6:]
else "Tesla Model {} {}".format(str(self._vin[3]).upper(), self.type)
)

def _uniq_name(self):
def _uniq_name(self) -> Text:
return "Tesla Model {} {} {}".format(
str(self._vin[3]).upper(), self._vin[-6:], self.type
)

def id(self):
def id(self) -> int:
# pylint: disable=invalid-name
"""Return the id of this Vehicle."""
return self._id

def vehicle_id(self):
def vehicle_id(self) -> int:
"""Return the vehicle_id of this Vehicle."""
return self._vehicle_id

def car_name(self):
def car_name(self) -> Text:
"""Return the car name of this Vehicle."""
return (
self._display_name
Expand All @@ -80,21 +80,21 @@ def car_name(self):
)

@property
def car_version(self):
def car_version(self) -> Text:
"""Return the software version of this Vehicle."""
return self._car_version

@property
def car_type(self):
def car_type(self) -> Text:
"""Return the type of this Vehicle."""
return self._car_type

@property
def sentry_mode_available(self):
def sentry_mode_available(self) -> bool:
"""Return True if sentry mode is available on this Vehicle."""
return self._sentry_mode_available

def assumed_state(self):
def assumed_state(self) -> bool:
# pylint: disable=protected-access
"""Return whether the data is from an online vehicle."""
return not self._controller.car_online[self.id()] and (
Expand All @@ -103,7 +103,9 @@ def assumed_state(self):
> self._controller.update_interval
)

async def async_update(self, wake_if_asleep=False, force=False):
async def async_update(
self, wake_if_asleep: bool = False, force: bool = False
) -> None:
"""Update the vehicle data."""
await self._controller.update(
self.id(), wake_if_asleep=wake_if_asleep, force=force
Expand All @@ -115,11 +117,11 @@ async def async_update(self, wake_if_asleep=False, force=False):
self._sentry_mode_available = state["sentry_mode_available"]

@staticmethod
def is_armable():
def is_armable() -> bool:
"""Return whether the data is from an online vehicle."""
return False

@staticmethod
def is_armed():
def is_armed() -> bool:
"""Return whether the vehicle is armed."""
return False
18 changes: 9 additions & 9 deletions tests/unit_tests/test_charger_connection_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_get_value_on_init(monkeypatch):
_data = _mock.data_request_vehicle()
_sensor = ChargerConnectionSensor(_data, _controller)

assert not _sensor is None
assert _sensor is not None
assert _sensor.get_value() is None


Expand All @@ -46,8 +46,8 @@ async def test_get_value_after_update(monkeypatch):

await _sensor.async_update()

assert not _sensor is None
assert not _sensor.get_value() is None
assert _sensor is not None
assert _sensor.get_value() is not None
assert _sensor.get_value()


Expand All @@ -59,13 +59,13 @@ async def test_get_value_on(monkeypatch):
_controller = Controller(None)

_data = _mock.data_request_vehicle()
_sensor = ChargerConnectionSensor(_data, _controller)
_data["charge_state"]["charging_state"] = "Charging"
_sensor = ChargerConnectionSensor(_data, _controller)

await _sensor.async_update()

assert not _sensor is None
assert not _sensor.get_value() is None
assert _sensor is not None
assert _sensor.get_value() is not None
assert _sensor.get_value()


Expand All @@ -77,11 +77,11 @@ async def test_get_value_off(monkeypatch):
_controller = Controller(None)

_data = _mock.data_request_vehicle()
_sensor = ChargerConnectionSensor(_data, _controller)
_data["charge_state"]["charging_state"] = "Disconnected"
_sensor = ChargerConnectionSensor(_data, _controller)

await _sensor.async_update()

assert not _sensor is None
assert not _sensor.get_value() is None
assert _sensor is not None
assert _sensor.get_value() is not None
assert not _sensor.get_value()
14 changes: 7 additions & 7 deletions tests/unit_tests/test_parking_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_get_value_on_init(monkeypatch):
_data = _mock.data_request_vehicle()
_sensor = ParkingSensor(_data, _controller)

assert not _sensor is None
assert _sensor is not None
assert _sensor.get_value() is None


Expand All @@ -45,8 +45,8 @@ async def test_get_value_after_update(monkeypatch):

await _sensor.async_update()

assert not _sensor is None
assert not _sensor.get_value() is None
assert _sensor is not None
assert _sensor.get_value() is not None
assert _sensor.get_value()


Expand All @@ -63,8 +63,8 @@ async def test_get_value_on(monkeypatch):

await _sensor.async_update()

assert not _sensor is None
assert not _sensor.get_value() is None
assert _sensor is not None
assert _sensor.get_value() is not None
assert _sensor.get_value()


Expand All @@ -81,6 +81,6 @@ async def test_get_value_off(monkeypatch):

await _sensor.async_update()

assert not _sensor is None
assert not _sensor.get_value() is None
assert _sensor is not None
assert _sensor.get_value() is not None
assert not _sensor.get_value()
33 changes: 18 additions & 15 deletions tests/unit_tests/test_vehicle_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,29 @@ def test_values_on_init(monkeypatch):
_data = _mock.data_request_vehicle()
_device = VehicleDevice(_data, _controller)

assert not _device is None
assert _device is not None

assert not _device.car_name() is None
assert _device.car_name() is not None
assert _device.car_name() == "Nikola 2.0"

assert not _device.car_type is None
assert _device.car_type is not None
assert _device.car_type == "Model S"

assert not _device.car_version is None
assert _device.car_version is not None
assert _device.car_version == ""

assert not _device.id() is None
assert _device.id() is not None
assert _device.id() == 12345678901234567

assert not _device.sentry_mode_available is None
assert _device.sentry_mode_available is not None
assert _device.sentry_mode_available

assert not _device.vehicle_id is None
assert _device.vehicle_id is not None
assert _device.vehicle_id() == 1234567890

assert not _device.update_available
assert _device.update_version is None


@pytest.mark.asyncio
async def test_values_after_update(monkeypatch):
Expand All @@ -74,24 +77,24 @@ async def test_values_after_update(monkeypatch):

await _device.async_update()

assert not _device is None
assert _device is not None

assert not _device.car_name() is None
assert _device.car_name() == "Nikola 2.0"

assert not _device.car_type is None
assert _device.car_type is not None
assert _device.car_type == "Model S"

assert not _device.car_version is None
assert _device.car_version is not None
assert _device.car_version == "2019.40.2.1 38f55d9f9205"

assert not _device.id() is None
assert _device.id() is not None
assert _device.id() == 12345678901234567

assert not _device.sentry_mode_available is None
assert _device.sentry_mode_available is not None
assert _device.sentry_mode_available

assert not _device.vehicle_id is None
assert _device.vehicle_id is not None
assert _device.vehicle_id() == 1234567890


Expand All @@ -113,7 +116,7 @@ async def test_assumed_state_online(monkeypatch):

await _device.async_update()

assert not _device is None
assert _device is not None
assert not _device.assumed_state() is None
assert not _device.assumed_state()

Expand All @@ -136,6 +139,6 @@ async def test_assumed_state_offline(monkeypatch):

await _device.async_update()

assert not _device is None
assert _device is not None
assert not _device.assumed_state() is None
assert _device.assumed_state()

0 comments on commit 7ac9c0b

Please sign in to comment.