Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
bremor authored Oct 18, 2020
1 parent 97e8919 commit b6cc01a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
_LOGGER = logging.getLogger(__name__)

class Connector:
"""mydlink cloud connector."""
"""Public Transport Victoria connector."""

manufacturer = "Demonstration Corp"

Expand Down Expand Up @@ -48,7 +48,7 @@ async def _init(self):
await self.async_update()

async def async_route_types(self):
"""Test credentials for Public Transport Victoria API."""
"""Get route types from Public Transport Victoria API."""
url = build_URL(self.id, self.api_key, ROUTE_TYPES_PATH)

async with aiohttp.ClientSession() as session:
Expand All @@ -63,7 +63,7 @@ async def async_route_types(self):
return route_types

async def async_routes(self, route_type):
"""Test credentials for Public Transport Victoria API."""
"""Get routes from Public Transport Victoria API."""
url = build_URL(self.id, self.api_key, ROUTES_PATH.format(route_type))

async with aiohttp.ClientSession() as session:
Expand All @@ -80,7 +80,7 @@ async def async_routes(self, route_type):
return routes

async def async_directions(self, route):
"""Test credentials for Public Transport Victoria API."""
"""Get directions from Public Transport Victoria API."""
url = build_URL(self.id, self.api_key, DIRECTIONS_PATH.format(route))

async with aiohttp.ClientSession() as session:
Expand All @@ -97,7 +97,7 @@ async def async_directions(self, route):
return directions

async def async_stops(self, route):
"""Test credentials for Public Transport Victoria API."""
"""Get stops from Public Transport Victoria API."""
url = build_URL(self.id, self.api_key, STOPS_PATH.format(route, self.route_type))

async with aiohttp.ClientSession() as session:
Expand Down Expand Up @@ -145,4 +145,4 @@ def convert_utc_to_local(utc):
d = datetime.datetime.strptime(utc, '%Y-%m-%dT%H:%M:%SZ')
d = d.replace(tzinfo=datetime.timezone.utc)
d = d.astimezone()
return d.strftime('%I:%M %p')
return d.strftime('%I:%M %p')
7 changes: 2 additions & 5 deletions custom_components/public_transport_victoria/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,14 @@


async def async_setup(hass: HomeAssistant, config: dict):
"""Set up the MyDlink component."""
# Ensure our name space for storing objects is a known type. A dict is
# common/preferred as it allows a separate instance of your class for each
# instance that has been created in the UI.
"""Set up the Public Transport Victoria component."""
hass.data.setdefault(DOMAIN, {})

return True


async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up MyDlink from a config entry."""
"""Set up Public Transport Victoria from a config entry."""
connector = Connector(hass,
entry.data[CONF_ID],
entry.data[CONF_API_KEY],
Expand Down
4 changes: 2 additions & 2 deletions custom_components/public_transport_victoria/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
async def async_step_user(self, user_input=None):
"""Handle the initial step."""
data_schema = vol.Schema({
vol.Required(CONF_ID, default="3000906"): str,
vol.Required(CONF_API_KEY, default="542fbf84-930b-467c-844d-21d74f15c38a"): str,
vol.Required(CONF_ID): str,
vol.Required(CONF_API_KEY): str,
})

errors = {}
Expand Down
3 changes: 1 addition & 2 deletions custom_components/public_transport_victoria/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"name": "Public Transport Victoria",
"config_flow": true,
"documentation": "https://github.com/bremor/public_transport_victoria",
"issue_tracker": "https://github.com/bremor/public_transport_victoria/issues",
"requirements": [],
"dependencies": [],
"codeowners": ["@bremor"]
}
}
40 changes: 3 additions & 37 deletions custom_components/public_transport_victoria/sensor.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""Platform for sensor integration."""
import datetime
import logging

from homeassistant.helpers.entity import Entity
from .const import DOMAIN

_LOGGER = logging.getLogger(__name__)
SCAN_INTERVAL = datetime.timedelta(minutes=10)

# See cover.py for more details.
# Note how both entities for each roller sensor (battry and illuminance) are added at
# the same time to the same list. This way only a single async_add_devices call is
# required.
async def async_setup_entry(hass, config_entry, async_add_devices):
"""Add sensors for passed config_entry in HA."""
connector = hass.data[DOMAIN][config_entry.entry_id]
Expand All @@ -21,9 +19,6 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
async_add_devices(new_devices)


# This base class shows the common properties and methods for a sensor as used in this
# example. See each sensor for further details about properties and methods that
# have been overridden.
class Sensor(Entity):
"""Representation of a Public Transport Victoria Sensor."""

Expand All @@ -32,36 +27,6 @@ def __init__(self, connector, number):
self._connector = connector
self._number = number

# To link this entity to the cover device, this property must return an
# identifiers value matching that used in the cover, but no other information such
# as name. If name is returned, this entity will then also become a device in the
# HA UI.
#@property
#def device_info(self):
# """Return information to link this entity with the correct device."""
# #return {"identifiers": {(DOMAIN, self._roller.roller_id)}}
# return {"identifiers": {(DOMAIN, "test_123")}}

# This property is important to let HA know if this entity is online or not.
# If an entity is offline (return False), the UI will refelect this.
# @property
# def available(self) -> bool:
# """Return True if roller and hub is available."""
# #return self._roller.online and self._roller.hub.online
# return True

# async def async_added_to_hass(self):
# """Run when this Entity has been added to HA."""
# # Sensors should also register callbacks to HA when their state changes
# #self._roller.register_callback(self.async_write_ha_state)
# pass

# async def async_will_remove_from_hass(self):
# """Entity being removed from hass."""
# # The opposite of async_added_to_hass. Remove any registered call backs here.
# #self._roller.remove_callback(self.async_write_ha_state)
# pass

# The value of this sensor.
@property
def state(self):
Expand Down Expand Up @@ -97,5 +62,6 @@ def device_state_attributes(self):

async def async_update(self):
"""Return the state attributes of the device."""
_LOGGER.debug("Update has been called")
await self._connector.async_update()

0 comments on commit b6cc01a

Please sign in to comment.