Skip to content

Commit

Permalink
the sensor name update was to be concidered a breaking, added config …
Browse files Browse the repository at this point in the history
…value to avoid problem
  • Loading branch information
iesus committed Nov 3, 2020
1 parent 9ef385e commit 7910233
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions custom_components/resrobot/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CONF_MAX_JOURNEYS = 'max_journeys'
CONF_SENSORS = 'sensors'
CONF_STOP_ID = 'stop_id'
CONF_UPDATE_NAME = 'update_name'
CONF_KEY = 'key'
CONF_FILTER = 'filter'
CONF_FILTER_LINE = 'line'
Expand All @@ -48,6 +49,7 @@
vol.Optional(CONF_SENSORS, default=3): cv.positive_int,
vol.Required(CONF_STOP_ID): cv.positive_int,
vol.Optional(CONF_NAME): cv.string,
vol.Optional(CONF_UPDATE_NAME): cv.boolean,
vol.Optional(CONF_UNIT): cv.string,
vol.Optional(CONF_TIME_OFFSET): cv.positive_int,
vol.Optional(CONF_MAX_JOURNEYS, default=20): cv.positive_int,
Expand Down Expand Up @@ -77,6 +79,7 @@ async def async_setup_platform(hass, config, async_add_devices, discovery_info=N
departure.get(CONF_SENSORS),
departure.get(CONF_UNIT),
departure.get(CONF_NAME),
departure.get(CONF_UPDATE_NAME),
departure.get(CONF_STOP_ID),
departure.get(CONF_MAX_JOURNEYS),
departure.get(CONF_TIME_OFFSET),
Expand All @@ -85,8 +88,9 @@ async def async_setup_platform(hass, config, async_add_devices, discovery_info=N
)

async def add_sensors(hass, config, async_add_devices, api_key, fetch_interval,
number_of_sensors, unit_of_measurement, name, location,
max_journeys, time_offset, filter, discovery_info=None):
number_of_sensors, unit_of_measurement, name, update_name,
location, max_journeys, time_offset, filter,
discovery_info=None):
method = 'GET'
payload = ''
auth = None
Expand All @@ -111,6 +115,7 @@ async def add_sensors(hass, config, async_add_devices, api_key, fetch_interval,
sensors.append(entityRepresentation(hass, helper, entityName, i,
number_of_sensors,
unit_of_measurement,
update_name,
time_offset))
async_add_devices(sensors, True)

Expand Down Expand Up @@ -231,7 +236,7 @@ class entityRepresentation(Entity):

def __init__(self, hass, helper, name, k,
number_of_sensors, unit_of_measurement,
time_offset):
update_name, time_offset):

"""Initialize a sensor."""
self._hass = hass
Expand All @@ -241,6 +246,7 @@ def __init__(self, hass, helper, name, k,
self._s = number_of_sensors
self._unit = unit_of_measurement if unit_of_measurement else "time"
self._time_offset = time_offset
self._update_name = update_name
self._state = "Unavailable"
self._attributes = {}

Expand Down Expand Up @@ -336,7 +342,8 @@ async def async_update(self):

for k,data in enumerate(trips):
if (k == self._k):
self._name = data["name"]
if self._update_name:
self._name = data["name"]
self._attributes.update({"name": data["name"]})
self._attributes.update({"line": data["transportNumber"]})
if "rTime" in data:
Expand Down
1 change: 1 addition & 0 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ You can also filter the results and adjust how many sensors you want:
fetch_interval: 10 # Minutes between updating the data
- stop_id: STOP_ID # Look in the stops.txt file
name: Next bus towards the city # Name of sensor
update_name: True # If true name will be something like "Länstrafik buss 1" instead of next bus towards the city_0
max_journeys: 20 # Number of departures to fetch
sensors: 5 # Number of sensors to create
time_offset: 10 # Do not fetch from NOW but now+n minutes, also consider the departed n minutes before it actually departs, e.g. time it takes you to walk to the bus)
Expand Down

0 comments on commit 7910233

Please sign in to comment.