diff --git a/.github/ISSUE_TEMPLATE/bug_replort.yml b/.github/ISSUE_TEMPLATE/bug_report.yml similarity index 100% rename from .github/ISSUE_TEMPLATE/bug_replort.yml rename to .github/ISSUE_TEMPLATE/bug_report.yml diff --git a/custom_components/gasbuddy/const.py b/custom_components/gasbuddy/const.py index a300cd9..a5ab616 100644 --- a/custom_components/gasbuddy/const.py +++ b/custom_components/gasbuddy/const.py @@ -18,6 +18,7 @@ # hass.data attribues ATTR_IMAGEURL = "image_url" +ATTR_LIMIT = "limit" COORDINATOR = "coordinator" DOMAIN = "gasbuddy" VERSION = "1.0" diff --git a/custom_components/gasbuddy/manifest.json b/custom_components/gasbuddy/manifest.json index 2ad55ce..10d5b1d 100644 --- a/custom_components/gasbuddy/manifest.json +++ b/custom_components/gasbuddy/manifest.json @@ -7,7 +7,7 @@ "import_executor": true, "iot_class": "cloud_polling", "issue_tracker": "https://github.com/firstof9/ha-gasbuddy/issues", - "requirements": ["py-gasbuddy==0.2.9"], + "requirements": ["py_gasbuddy==0.2.10"], "version": "0.0.0-dev" } \ No newline at end of file diff --git a/custom_components/gasbuddy/services.py b/custom_components/gasbuddy/services.py index 165916a..954baea 100644 --- a/custom_components/gasbuddy/services.py +++ b/custom_components/gasbuddy/services.py @@ -15,7 +15,7 @@ ) from homeassistant.helpers import config_validation as cv -from .const import DOMAIN, SERVICE_LOOKUP_GPS +from .const import ATTR_LIMIT, DOMAIN, SERVICE_LOOKUP_GPS _LOGGER = logging.getLogger(__name__) @@ -42,6 +42,9 @@ def async_register(self) -> None: schema=vol.Schema( { vol.Required(ATTR_ENTITY_ID): cv.entity_ids, + vol.Optional(ATTR_LIMIT): vol.All( + vol.Coerce(int), vol.Range(min=1, max=99) + ), } ), supports_response=SupportsResponse.ONLY, @@ -51,6 +54,10 @@ def async_register(self) -> None: async def _price_lookup_gps(self, service: ServiceCall) -> ServiceResponse: """Set the override.""" entity_ids = service.data[ATTR_ENTITY_ID] + limit = 5 + + if ATTR_LIMIT in service.data: + limit = service.data[ATTR_LIMIT] results = {} for entity_id in entity_ids: @@ -58,7 +65,9 @@ async def _price_lookup_gps(self, service: ServiceCall) -> ServiceResponse: entity = self.hass.states.get(entity_id) lat = entity.attributes[ATTR_LATITUDE] lon = entity.attributes[ATTR_LONGITUDE] - results[entity_id] = await GasBuddy().price_lookup_gps(lat=lat, lon=lon) + results[entity_id] = await GasBuddy().price_lookup_gps( + lat=lat, lon=lon, limit=limit + ) except Exception as err: _LOGGER.error("Error checking prices: %s", err) diff --git a/custom_components/gasbuddy/services.yaml b/custom_components/gasbuddy/services.yaml index 696d260..3b71366 100644 --- a/custom_components/gasbuddy/services.yaml +++ b/custom_components/gasbuddy/services.yaml @@ -3,4 +3,6 @@ lookup_gps: description: List gas prices based on GPS coordinates of device tracker. target: entity: - domain: device_tracker \ No newline at end of file + domain: + - device_tracker + - person \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 634c4fc..224f6e4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -py-gasbuddy==0.2.9 +py_gasbuddy==0.2.10 diff --git a/tests/test_services.py b/tests/test_services.py index 4625414..989d271 100644 --- a/tests/test_services.py +++ b/tests/test_services.py @@ -6,7 +6,7 @@ from homeassistant.const import ATTR_ENTITY_ID, ATTR_LATITUDE, ATTR_LONGITUDE from pytest_homeassistant_custom_component.common import MockConfigEntry -from custom_components.gasbuddy.const import DOMAIN +from custom_components.gasbuddy.const import ATTR_LIMIT, DOMAIN from tests.common import load_fixture from .const import CONFIG_DATA @@ -68,6 +68,22 @@ async def test_lookup_gps( == "2024-11-18T21:58:38.859Z" ) + mock_aioclient.post( + TEST_URL, + status=200, + body=load_fixture("results.json"), + ) + + response = await hass.services.async_call( + DOMAIN, + SERVICE_LOOKUP_GPS, + {ATTR_ENTITY_ID: entity_id, ATTR_LIMIT: 10}, + blocking=True, + return_response=True, + ) + + assert len(response[entity_id]["results"]) == 10 + mock_aioclient.post( TEST_URL, status=400,