Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RMV public transport sensor #15814

Merged
merged 27 commits into from
Aug 10, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c3f61e0
Add new public transport sensor for RMV (Rhein-Main area).
cgtobi Aug 2, 2018
b9b59aa
Add required module.
cgtobi Aug 2, 2018
41c34ea
Fix naming problem.
cgtobi Aug 2, 2018
f9e88b6
Add unit test.
cgtobi Aug 3, 2018
221167e
Update dependency version to 0.0.5.
cgtobi Aug 3, 2018
504049b
Add new requirements.
cgtobi Aug 3, 2018
db76dd0
Fix variable name.
cgtobi Aug 3, 2018
2d9c122
Fix issues pointed out in review.
cgtobi Aug 5, 2018
485ae89
Remove unnecessary code.
cgtobi Aug 5, 2018
6fcc48d
Fix linter error.
cgtobi Aug 5, 2018
741a711
Fix config value validation.
cgtobi Aug 6, 2018
1403293
Replace minutes as state by departure timestamp. (see ##14983)
cgtobi Aug 6, 2018
f67f22e
More work on the timestamp. (see ##14983)
cgtobi Aug 7, 2018
74117c3
Revert timestamp work until #14983 gets merged.
cgtobi Aug 7, 2018
2accb78
Simplify product validation.
cgtobi Aug 7, 2018
661bad1
Remove redundant code.
cgtobi Aug 7, 2018
26f1227
Address code change requests.
cgtobi Aug 9, 2018
b714364
Address more code change requests.
cgtobi Aug 9, 2018
8be8b07
Address even more code change requests.
cgtobi Aug 9, 2018
d21cec3
Simplify destination check.
cgtobi Aug 9, 2018
4341b8a
Fix linter problem.
cgtobi Aug 9, 2018
72c3b7e
Bump dependency version to 0.0.7.
cgtobi Aug 9, 2018
9f29d30
Name variable more explicit.
cgtobi Aug 10, 2018
844c439
Only query once a minute.
cgtobi Aug 10, 2018
cacfd46
Update test case.
cgtobi Aug 10, 2018
a9949a4
Fix config validation.
cgtobi Aug 10, 2018
1642b47
Remove unneeded import.
cgtobi Aug 10, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion homeassistant/components/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
from homeassistant.const import (
DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TEMPERATURE)
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TIMESTAMP)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -28,6 +28,7 @@
DEVICE_CLASS_HUMIDITY, # % of humidity in the air
DEVICE_CLASS_ILLUMINANCE, # current light level (lx/lm)
DEVICE_CLASS_TEMPERATURE, # temperature (C/F)
DEVICE_CLASS_TIMESTAMP, # ISO formatted timestamp
]

DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(DEVICE_CLASSES))
Expand Down
17 changes: 10 additions & 7 deletions homeassistant/components/sensor/rmvtransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.helpers.entity import Entity
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import (
CONF_NAME, ATTR_ATTRIBUTION, STATE_UNKNOWN
CONF_NAME, ATTR_ATTRIBUTION, DEVICE_CLASS_TIMESTAMP, STATE_UNKNOWN
)

REQUIREMENTS = ['PyRMVtransport==0.0.6']
Expand Down Expand Up @@ -130,8 +130,7 @@ def state_attributes(self):
result = {
'next_departures': [val for val in self.data.departures[1:]],
'direction': self.data.departures[0].get('direction'),
'line': self.data.departures[0].get('number'),
'minutes': self.data.departures[0].get('minutes'),
'line': self.data.departures[0].get('line'),
'departure_time':
self.data.departures[0].get('departure_time'),
'product': self.data.departures[0].get('product'),
Expand All @@ -146,9 +145,12 @@ def icon(self):
return self._icon

@property
def unit_of_measurement(self):
"""Return the unit this state is expressed in."""
return "min"
def device_class(self):
"""Return the device class of the sensor."""
return DEVICE_CLASS_TIMESTAMP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not do that. You should first implement it as an existing device class, wait until #14983 merged, then open anther PR to change your sensor's device class. Otherwise I have to put your PR on hold until the dependency satisfied.

I don't know when #14983 will merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

# def unit_of_measurement(self):
# """Return the unit this state is expressed in."""
# return "min"

def update(self):
"""Get the latest data and update the state."""
Expand Down Expand Up @@ -211,8 +213,9 @@ def update(self):
continue
elif journey['minutes'] < self._timeoffset:
continue
for k in ['direction', 'number', 'departure_time', 'product']:
for k in ['direction', 'departure_time', 'product']:
_nextdep[k] = journey.get(k, '')
_nextdep['line'] = journey.get('number', '')
_deps.append(_nextdep)
if len(_deps) > self._maxjourneys:
break
Expand Down
1 change: 1 addition & 0 deletions homeassistant/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
DEVICE_CLASS_HUMIDITY = 'humidity'
DEVICE_CLASS_ILLUMINANCE = 'illuminance'
DEVICE_CLASS_TEMPERATURE = 'temperature'
DEVICE_CLASS_TIMESTAMP = 'timestamp'

# #### STATES ####
STATE_ON = 'on'
Expand Down