Skip to content

Commit

Permalink
feat: add method plants_detail
Browse files Browse the repository at this point in the history
  • Loading branch information
hudsonbrendon committed Jan 29, 2025
1 parent fd96bbd commit 2f9ba36
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 0 deletions.
15 changes: 15 additions & 0 deletions solar_plus_intelbras/solar_plus_intelbras.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ def plants(self) -> dict:
)
return response.json()

def plants_detail(self, plant_id: int) -> dict:
"""Return the plant.
Args:
plant_id (int): A plant id.
Returns:
dict: A dictionary with the plants.
"""
response = requests.get(
f"{self.base_api_url}{EndpointEnum.PLANTS.value}/{plant_id}",
headers={"Authorization": f"Bearer {self.token}", "plus": self.plus},
)
return response.json()

def records(
self,
plant_id: int,
Expand Down
152 changes: 152 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,158 @@ def plants() -> dict:
}


@pytest.fixture
def plants_detail() -> dict:
return {
"id": 3114,
"picture": "",
"name": "Test Test",
"userOwnerID": 6111,
"userOwner": {
"id": 6333,
"createdAt": "2024-12-16T14:49:56.610698-03:00",
"updatedAt": "2025-01-29T10:40:41.320143-03:00",
"lastLogin": "2025-01-29 10:40:40.910796618 -0300 -03 m=+8623.843616898",
"email": "[email protected]",
"clientID": "",
"clientSecret": "",
"picture": "",
"registrationToken": "eOdX33333EYImEPQ-_WFdO:APA91bE3Og14CBS0Ub-r5C1NhuxL8GF0HpO0i2xiXaFDcgqUs8po0czSq9-PhGgBRsPS4ogN8mYARWBLIE_UM6rlECpSSNwWT98ELCFiZzX9uEZhOToEK7Q",
"passwordRecoveryCode": "",
"passwordRecoveryExpiresAt": {
"Time": "0001-01-01T00:00:00Z",
"Valid": False,
},
"name": "Hudson Brendon",
"cpf": "",
"phone": "",
"activationCode": "223468ddf743d09a88e66f0efa06b015",
"activatedAt": {"Time": "2024-12-16T14:49:56.608105-03:00", "Valid": True},
"sessions": None,
"pushesNotification": None,
"preferences": {
"currency": "BRL",
"timezone": "-3",
"temperatureUnit": "c",
"sendWeatherNotification": True,
"sendEnergyTodayNotification": True,
"sendAlertNotification": True,
},
},
"users": [],
"business_accounts": [
{
"id": 3367,
"createdAt": "2024-10-14T15:38:47.203353-03:00",
"updatedAt": "2025-01-29T10:12:02.123352-03:00",
"userOwnerID": 4205,
"userOwner": {
"id": 0,
"createdAt": "0001-01-01T00:00:00Z",
"updatedAt": "0001-01-01T00:00:00Z",
"lastLogin": "",
"email": "",
"clientID": "",
"clientSecret": "",
"picture": "",
"registrationToken": "",
"passwordRecoveryCode": "",
"passwordRecoveryExpiresAt": {
"Time": "0001-01-01T00:00:00Z",
"Valid": False,
},
"name": "",
"cpf": "",
"phone": "",
"activationCode": "",
"activatedAt": {"Time": "0001-01-01T00:00:00Z", "Valid": False},
"sessions": None,
"pushesNotification": None,
"preferences": {
"sendWeatherNotification": None,
"sendEnergyTodayNotification": None,
"sendAlertNotification": None,
},
},
"name": "Test",
"code": "11DE",
"cnpj": "36.689.111/0001-17",
"webSite": "",
"phone": "",
}
],
"weather": {
"current": {
"cloud": 50,
"is_day": 1,
"temp_c": 30.1,
"temp_f": 86.2,
"humidity": 70,
"wind_dir": "E",
"wind_kph": 15.1,
"condition": {
"code": 1003,
"icon": "//cdn.weatherapi.com/weather/64x64/day/116.png",
"text": "Parcialmente nublado",
},
"wind_degree": 80,
"last_updated": "2025-01-29 10:00",
"last_updated_epoch": 1738155600,
},
"location": {
"lat": 0,
"long": 0,
"name": "Test",
"tz_id": "America/Fortaleza",
"region": "Test",
"country": "Brazil",
"localtime": "2025-01-29 10:05",
"localtime_epoch": 1738155951,
},
},
"street": "Test",
"number": "",
"district": "Test",
"city": "Test",
"state": "SP",
"country": "BR",
"zip": "51155-810",
"latitude": -5.911442,
"longitude": -35.11916,
"online": True,
"offgrid": False,
"status": "NORMAL",
"price": 0.92,
"capacityInstalled": 5,
"modulesAmount": 10,
"last_record": "2025-01-29T10:20:02.499874-03:00",
"installed_at": "0000-12-31T20:53:32-03:06",
"createdAt": "2024-12-16T14:49:57.108865-03:00",
"updatedAt": "2025-01-29T10:20:02.537353-03:00",
"metrics": {
"energyToday": 5.2,
"energyTotal": 299,
"currentPower": 4993,
"totalEconomy": 275.08000499010086,
"todayEconomy": 4.784000086784363,
"economyOfLast30": 274.43600497841834,
"yearEconomy": 0,
"energyOfLast30": 298.3,
"savedCo2": 101.83940124511719,
"savedTrees": 0.10183940082788467,
"savedCoal": 0.11959999799728394,
},
"components": {
"inverters": 1,
"dataloggers": 1,
"modules": 0,
"alerts": 5,
"todayAlerts": 0,
"chargeControllers": 0,
},
}


@pytest.fixture
def records_today() -> dict:
return {
Expand Down
47 changes: 47 additions & 0 deletions tests/test_solar_plus_intelbras.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,53 @@ def test_shouldnt_return_plants_without_authentication(
solar_plus_intelbras.plants()


class TestSolarPlusIntelbrasPlantsDetail:
def test_should_return_plants_detail(
self,
requests_mock: Mocker,
solar_plus_intelbras: SolarPlusIntelbras,
plants_detail: dict,
login_response: dict,
) -> None:
requests_mock.post(
"https://ens-server.intelbras.com.br/api/login",
json=login_response,
status_code=200,
)

requests_mock.get(
"https://ens-server.intelbras.com.br/api/plants/1",
json=plants_detail,
status_code=200,
)
assert isinstance(solar_plus_intelbras.plants_detail(plant_id=1), dict)
assert solar_plus_intelbras.plants_detail(plant_id=1) == plants_detail

def test_shouldnt_return_plants_detail_without_authentication(
self, solar_plus_intelbras: SolarPlusIntelbras
) -> None:
with pytest.raises(Exception):
solar_plus_intelbras.plants_detail(plant_id=1)

def test_shouldnt_return_plants_detail_without_plant_id(
self, solar_plus_intelbras: SolarPlusIntelbras
) -> None:
with pytest.raises(Exception):
solar_plus_intelbras.plants_detail()

def test_shouldnt_return_plants_detail_string(
self, solar_plus_intelbras: SolarPlusIntelbras
) -> None:
with pytest.raises(Exception):
solar_plus_intelbras.plants_detail(plant_id="1")

def test_shouldnt_return_plants_detail_float(
self, solar_plus_intelbras: SolarPlusIntelbras
) -> None:
with pytest.raises(Exception):
solar_plus_intelbras.plants_detail(plant_id=1.0)


class TestSolarPlusIntelbrasRecords:
def test_should_return_records_today(
self,
Expand Down

0 comments on commit 2f9ba36

Please sign in to comment.