From b6cc01ade7041e8e4deb5b97169dcfbb947df5d8 Mon Sep 17 00:00:00 2001 From: bremor <34525505+bremor@users.noreply.github.com> Date: Sun, 18 Oct 2020 23:24:15 +1100 Subject: [PATCH] Add files via upload --- .../public_transport_victoria.py | 12 +++--- .../public_transport_victoria/__init__.py | 7 +--- .../public_transport_victoria/config_flow.py | 4 +- .../public_transport_victoria/manifest.json | 3 +- .../public_transport_victoria/sensor.py | 40 ++----------------- 5 files changed, 14 insertions(+), 52 deletions(-) diff --git a/custom_components/public_transport_victoria/PublicTransportVictoria/public_transport_victoria.py b/custom_components/public_transport_victoria/PublicTransportVictoria/public_transport_victoria.py index 985f326..c708a0f 100644 --- a/custom_components/public_transport_victoria/PublicTransportVictoria/public_transport_victoria.py +++ b/custom_components/public_transport_victoria/PublicTransportVictoria/public_transport_victoria.py @@ -20,7 +20,7 @@ _LOGGER = logging.getLogger(__name__) class Connector: - """mydlink cloud connector.""" + """Public Transport Victoria connector.""" manufacturer = "Demonstration Corp" @@ -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: @@ -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: @@ -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: @@ -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: @@ -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') \ No newline at end of file diff --git a/custom_components/public_transport_victoria/__init__.py b/custom_components/public_transport_victoria/__init__.py index 6b9522b..b621340 100644 --- a/custom_components/public_transport_victoria/__init__.py +++ b/custom_components/public_transport_victoria/__init__.py @@ -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], diff --git a/custom_components/public_transport_victoria/config_flow.py b/custom_components/public_transport_victoria/config_flow.py index 797679a..b447d7a 100644 --- a/custom_components/public_transport_victoria/config_flow.py +++ b/custom_components/public_transport_victoria/config_flow.py @@ -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 = {} diff --git a/custom_components/public_transport_victoria/manifest.json b/custom_components/public_transport_victoria/manifest.json index 61992db..83ebcca 100644 --- a/custom_components/public_transport_victoria/manifest.json +++ b/custom_components/public_transport_victoria/manifest.json @@ -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"] -} +} \ No newline at end of file diff --git a/custom_components/public_transport_victoria/sensor.py b/custom_components/public_transport_victoria/sensor.py index 1734064..8f63f6c 100644 --- a/custom_components/public_transport_victoria/sensor.py +++ b/custom_components/public_transport_victoria/sensor.py @@ -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] @@ -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.""" @@ -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): @@ -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()